Code samples for Image to PDF Converter
Product update
This product has been replaced by the Pdftools SDK.
Image to PDF Converter lets you convert image files to PDF documents, including PDF/A with searchable output files. Here you'll find some examples of how to integrate the code in your development.
Conversion
Convert Image to PDF and embed metadata
1// Create the converter
2pConverter = Img2PdfCreateObject();
3
4// Create output file
5if (!Img2PdfCreate(pConverter, szOutPath, _T(""), _T(""), ePermNoEncryption))
6{
7 _tprintf(_T("Output file %s cannot be created. %s (ErrorCode: 0x%08x).\n"), szOutPath, Img2PdfGetErrorMessage(pConverter), Img2PdfGetErrorCode(pConverter));
8 iReturnValue = 1;
9 goto cleanup;
10}
11
12// Set xmp metadata
13Img2PdfSetMetadata(pConverter, szMetaFile);
14
15// Convert pages from input image to PDF
16if (!Img2PdfCreatePageFromImage(pConverter, szInPath))
17{
18 _tprintf(_T("Pages cannot be created from image input %s. %s (ErrorCode: 0x%08x).\n"), szInPath, Img2PdfGetErrorMessage(pConverter), Img2PdfGetErrorCode(pConverter));
19 iReturnValue = 1;
20 goto cleanup;
21}
22
23// Close output file
24if (!Img2PdfClose(pConverter))
25{
26 _tprintf(_T("Output file %s cannot be closed. %s (ErrorCode: 0x%08x).\n"), szOutPath, Img2PdfGetErrorMessage(pConverter), Img2PdfGetErrorCode(pConverter));
27 iReturnValue = 1;
28 goto cleanup;
29}
30
1// Create the converter
2using (Img2Pdf converter = new Img2Pdf())
3{
4 // Create output file
5 if (!converter.Create(outPath, "", "", PDFPermission.ePermNoEncryption))
6 throw new Exception(String.Format("Output file {0} cannot be created. {1} " +
7 "(ErrorCode: 0x{2:x})", outPath, converter.ErrorMessage, converter.ErrorCode));
8
9 // Set xmp metadata
10 converter.SetMetadata(metaFile);
11
12 // Convert pages from input image to PDF
13 if (!converter.CreatePageFromImage(inPath))
14 throw new Exception(String.Format("Pages cannot be created from image input {0}. " +
15 "{1} (ErrorCode: 0x{2:x})", inPath, converter.ErrorMessage, converter.ErrorCode));
16
17 // Close output file
18 if (!converter.Close())
19 throw new Exception(String.Format("Output file {0} cannot be closed. " +
20 "{1} (ErrorCode: 0x{2:x})", outPath, converter.ErrorMessage, converter.ErrorCode));
21}
22
1// Create the converter
2converter = new Img2Pdf();
3
4// Create output file
5if (!converter.create(outPath, "", "", NativeLibrary.PERMISSION.ePermNoEncryption))
6 throw new Exception(String.format("Output file %s cannot be created. %s (ErrorCode: 0x%08x).",
7 outPath, converter.getErrorMessage(), converter.getErrorCode()));
8
9// Set xmp metadata
10converter.setMetadata(metaFile);
11
12// Convert pages from input image to PDF
13if (!converter.createPageFromImage(inPath))
14 throw new Exception(String.format("Pages cannot be created from image input %s. %s " +
15 "(ErrorCode: 0x%08x).", inPath, converter.getErrorMessage(), converter.getErrorCode()));
16
17// Close output file
18if (!converter.close())
19 throw new Exception(String.format("Output file %s cannot be closed. %s (ErrorCode: 0x%08x).",
20 outPath, converter.getErrorMessage(), converter.getErrorCode()));
21
Convert Image to PDF and set compression
1// Create the converter
2pConverter = Img2PdfCreateObject();
3
4// Create output file
5if (!Img2PdfCreate(pConverter, szOutPath, _T(""), _T(""), ePermNoEncryption))
6{
7 _tprintf(_T("Output file %s cannot be created. %s (ErrorCode: 0x%08x).\n"), szOutPath, Img2PdfGetErrorMessage(pConverter), Img2PdfGetErrorCode(pConverter));
8 iReturnValue = 1;
9 goto cleanup;
10}
11
12// Set compression
13Img2PdfSetContinuousCompression(pConverter, eCompression);
14
15// Set image quality
16Img2PdfSetImageQuality(pConverter, iQuality);
17
18// Convert pages from input image to PDF
19if (!Img2PdfCreatePageFromImage(pConverter, szInPath))
20{
21 _tprintf(_T("Pages cannot be created from image input %s. %s (ErrorCode: 0x%08x).\n"), szInPath, Img2PdfGetErrorMessage(pConverter), Img2PdfGetErrorCode(pConverter));
22 iReturnValue = 1;
23 goto cleanup;
24}
25
26// Close output file
27if (!Img2PdfClose(pConverter))
28{
29 _tprintf(_T("Output file %s cannot be closed. %s (ErrorCode: 0x%08x).\n"), szOutPath, Img2PdfGetErrorMessage(pConverter), Img2PdfGetErrorCode(pConverter));
30 iReturnValue = 1;
31 goto cleanup;
32}
33
1// Create the converter
2using (Img2Pdf converter = new Img2Pdf())
3{
4 // Create output file
5 if (!converter.Create(outPath, "", "", PDFPermission.ePermNoEncryption))
6 throw new Exception(String.Format("Output file {0} cannot be created. {1}" +
7 "(ErrorCode: 0x{2:x})", outPath, converter.ErrorMessage, converter.ErrorCode));
8
9 // Set compression
10 converter.ContinuousCompression = compression;
11
12 // Set image quality
13 converter.ImageQuality = quality;
14
15 // Convert pages from input image to PDF
16 if (!converter.CreatePageFromImage(inPath))
17 throw new Exception(String.Format("Pages cannot be created from image input {0}. " +
18 "{1} (ErrorCode: 0x{2:x})", inPath, converter.ErrorMessage, converter.ErrorCode));
19
20 // Close output file
21 if (!converter.Close())
22 throw new Exception(String.Format("Output file {0} cannot be closed. {1}" +
23 "(ErrorCode: 0x{2:x})", outPath, converter.ErrorMessage, converter.ErrorCode));
24}
25
1// Create the converter
2converter = new Img2Pdf();
3
4// Create output file
5if (!converter.create(outPath, "", "", NativeLibrary.PERMISSION.ePermNoEncryption))
6 throw new Exception(String.format("Output file %s cannot be created. %s (ErrorCode: 0x%08x).",
7 outPath, converter.getErrorMessage(), converter.getErrorCode()));
8
9// Set compression
10converter.setContinuousCompression(compression);
11
12// Set image quality
13converter.setImageQuality(quality);
14
15// Convert pages from input image to PDF
16if (!converter.createPageFromImage(inPath))
17 throw new Exception(String.format("Pages cannot be created from image input %s. %s " +
18 "(ErrorCode: 0x%08x).", inPath, converter.getErrorMessage(), converter.getErrorCode()));
19
20// Close output file
21if (!converter.close())
22 throw new Exception(String.format("Output file %s cannot be closed. %s (ErrorCode: 0x%08x).",
23 outPath, converter.getErrorMessage(), converter.getErrorCode()));
24
Convert Image to PDF/A
1// Create the converter
2pConverter = Img2PdfCreateObject();
3
4// Set PDF Compliance level
5Img2PdfSetCompliance(pConverter, eCompliance);
6
7// Create output file
8if (!Img2PdfCreate(pConverter, szOutPath, _T(""), _T(""), ePermNoEncryption))
9{
10 _tprintf(_T("Output file %s cannot be created. %s (ErrorCode: 0x%08x).\n"), szOutPath, Img2PdfGetErrorMessage(pConverter), Img2PdfGetErrorCode(pConverter));
11 iReturnValue = 1;
12 goto cleanup;
13}
14
15// Convert pages from input image to PDF
16if (!Img2PdfCreatePageFromImage(pConverter, szInPath))
17{
18 _tprintf(_T("Pages cannot be created from image input %s. %s (ErrorCode: 0x%08x).\n"), szInPath, Img2PdfGetErrorMessage(pConverter), Img2PdfGetErrorCode(pConverter));
19 iReturnValue = 1;
20 goto cleanup;
21}
22
23// Close output file
24if (!Img2PdfClose(pConverter))
25{
26 _tprintf(_T("Output file %s cannot be closed. %s (ErrorCode: 0x%08x).\n"), szOutPath, Img2PdfGetErrorMessage(pConverter), Img2PdfGetErrorCode(pConverter));
27 iReturnValue = 1;
28 goto cleanup;
29}
30
1// Create the converter
2using (Img2Pdf converter = new Img2Pdf())
3{
4 // Set PDF Compliance level
5 converter.Compliance = compliance;
6
7 // Create output file
8 if (!converter.Create(outPath, "", "", PDFPermission.ePermNoEncryption))
9 throw new Exception(String.Format("Output file {0} cannot be created. {1} "+
10 "(ErrorCode: 0x{2:x})", outPath, converter.ErrorMessage, converter.ErrorCode));
11
12 // Convert pages from input image to PDF
13 if (!converter.CreatePageFromImage(inPath))
14 throw new Exception(String.Format("Pages cannot be created from image input {0}. " +
15 "{1} (ErrorCode: 0x{2:x})", inPath, converter.ErrorMessage, converter.ErrorCode));
16
17 // Close output file
18 if (!converter.Close())
19 throw new Exception(String.Format("Output file {0} cannot be closed. " +
20 "{1} (ErrorCode: 0x{2:x})", outPath, converter.ErrorMessage, converter.ErrorCode));
21}
22
1// Create the converter
2converter = new Img2Pdf();
3
4// Set PDF Compliance level
5converter.setCompliance(compliance);
6
7// Create output file
8if (!converter.create(outPath, "", "", NativeLibrary.PERMISSION.ePermNoEncryption))
9 throw new Exception(String.format("Output file %s cannot be created. %s (ErrorCode: 0x%08x).",
10 outPath, converter.getErrorMessage(), converter.getErrorCode()));
11
12// Convert pages from input image to PDF
13if (!converter.createPageFromImage(inPath))
14 throw new Exception(String.format("Pages cannot be created from image input %s. %s " +
15 "(ErrorCode: 0x%08x).", inPath, converter.getErrorMessage(), converter.getErrorCode()));
16
17// Close output file
18if (!converter.close())
19 throw new Exception(String.format("Output file %s cannot be closed. %s (ErrorCode: 0x%08x).",
20 outPath, converter.getErrorMessage(), converter.getErrorCode()));
21
Convert Image to encrypted PDF
1pConverter = Img2PdfCreateObject();
2
3// Create encrypted output file
4if (!Img2PdfCreate(pConverter, szOutPath, szUserPW, szOwnerPW, ePermDigitalPrint | ePermPrint))
5{
6 _tprintf(_T("Output file %s cannot be created. %s (ErrorCode: 0x%08x).\n"), szOutPath, Img2PdfGetErrorMessage(pConverter), Img2PdfGetErrorCode(pConverter));
7 iReturnValue = 1;
8 goto cleanup;
9}
10
11// Convert pages from input image to PDF
12if (!Img2PdfCreatePageFromImage(pConverter, szInPath))
13{
14 _tprintf(_T("Pages cannot be created from image input %s. %s (ErrorCode: 0x%08x).\n"), szInPath, Img2PdfGetErrorMessage(pConverter), Img2PdfGetErrorCode(pConverter));
15 iReturnValue = 1;
16 goto cleanup;
17}
18
19// Close output file
20if (!Img2PdfClose(pConverter))
21{
22 _tprintf(_T("Output file %s cannot be closed. %s (ErrorCode: 0x%08x).\n"), szOutPath, Img2PdfGetErrorMessage(pConverter), Img2PdfGetErrorCode(pConverter));
23 iReturnValue = 1;
24 goto cleanup;
25}
26
1// Create the converter
2using (Img2Pdf converter = new Img2Pdf())
3{
4 // Create encrypted output file
5 if (!converter.Create(outPath, userPW, ownerPW, PDFPermission.ePermDigitalPrint |
6 PDFPermission.ePermPrint))
7 throw new Exception(String.Format("Output file {0} cannot be created. {1} " +
8 "(ErrorCode: 0x{2:x})", outPath, converter.ErrorMessage, converter.ErrorCode));
9
10 // Convert pages from input image to PDF
11 if (!converter.CreatePageFromImage(inPath))
12 throw new Exception(String.Format("Pages cannot be created from image input {0}. " +
13 "{1} (ErrorCode: 0x{2:x})", inPath, converter.ErrorMessage, converter.ErrorCode));
14
15 // Close output file
16 if (!converter.Close())
17 throw new Exception(String.Format("Output file {0} cannot be closed. {1} " +
18 "(ErrorCode: 0x{2:x})", outPath, converter.ErrorMessage, converter.ErrorCode));
19}
20
1// Create the converter
2converter = new Img2Pdf();
3
4// Create encrypted output file
5if (!converter.create(outPath, userPW, ownerPW, NativeLibrary.PERMISSION.ePermPrint |
6 NativeLibrary.PERMISSION.ePermDigitalPrint))
7 throw new Exception(String.format("Output file %s cannot be created. %s (ErrorCode: 0x%08x).",
8 outPath, converter.getErrorMessage(), converter.getErrorCode()));
9
10// Convert pages from input image to PDF
11if (!converter.createPageFromImage(inPath))
12 throw new Exception(String.format("Pages cannot be created from image input %s. %s " +
13 "(ErrorCode: 0x%08x).", inPath, converter.getErrorMessage(), converter.getErrorCode()));
14
15// Close output file
16if (!converter.close())
17 throw new Exception(String.format("Output file %s cannot be closed. %s (ErrorCode: 0x%08x).",
18 outPath, converter.getErrorMessage(), converter.getErrorCode()));
19
Convert Image to PDF and set InfoDictionary
1// Create the converter
2pConverter = Img2PdfCreateObject();
3
4// Create output file
5if (!Img2PdfCreate(pConverter, szOutPath, _T(""), _T(""), ePermNoEncryption))
6{
7 _tprintf(_T("Output file %s cannot be created. %s (ErrorCode: 0x%08x).\n"), szOutPath, Img2PdfGetErrorMessage(pConverter), Img2PdfGetErrorCode(pConverter));
8 iReturnValue = 1;
9 goto cleanup;
10}
11
12// Set info dictionary
13Img2PdfSetInfoEntry(pConverter, _T("Title"), _T("Your Title"));
14Img2PdfSetInfoEntry(pConverter, _T("Author"), _T("Your Author"));
15Img2PdfSetInfoEntry(pConverter, _T("Creator"), _T("Your Creator"));
16Img2PdfSetInfoEntry(pConverter, _T("Subject"), _T("Your Subject"));
17Img2PdfSetInfoEntry(pConverter, _T("Producer"), _T("Your Producer"));
18
19// Convert pages from input image to PDF
20if (!Img2PdfCreatePageFromImage(pConverter, szInPath))
21{
22 _tprintf(_T("Pages cannot be created from image input %s. %s (ErrorCode: 0x%08x).\n"), szInPath, Img2PdfGetErrorMessage(pConverter), Img2PdfGetErrorCode(pConverter));
23 iReturnValue = 1;
24 goto cleanup;
25}
26
27// Close output file
28if (!Img2PdfClose(pConverter))
29{
30 _tprintf(_T("Output file %s cannot be closed. %s (ErrorCode: 0x%08x).\n"), szOutPath, Img2PdfGetErrorMessage(pConverter), Img2PdfGetErrorCode(pConverter));
31 iReturnValue = 1;
32 goto cleanup;
33}
34
1// Create the converter
2using (Img2Pdf converter = new Img2Pdf())
3{
4 // Create output file
5 if (!converter.Create(outPath, "", "", PDFPermission.ePermNoEncryption))
6 throw new Exception(String.Format("Output file {0} cannot be created. {1}" +
7 "(ErrorCode: 0x{2:x})", outPath, converter.ErrorMessage, converter.ErrorCode));
8
9 // Set info dictionary
10 converter.SetInfoEntry("Title", "Your Title");
11 converter.SetInfoEntry("Author", "Your Author");
12 converter.SetInfoEntry("Creator", "Your Creator");
13 converter.SetInfoEntry("Subject", "Your Subject");
14 converter.SetInfoEntry("Producer", "Your Producer");
15
16 // Convert pages from input image to PDF
17 if (!converter.CreatePageFromImage(inPath))
18 throw new Exception(String.Format("Pages cannot be created from image input {0}. {1}" +
19 "(ErrorCode: 0x{2:x})", inPath, converter.ErrorMessage, converter.ErrorCode));
20
21 // Close output file
22 if (!converter.Close())
23 throw new Exception(String.Format("Output file {0} cannot be closed. {1} " +
24 "(ErrorCode: 0x{2:x})", outPath, converter.ErrorMessage, converter.ErrorCode));
25}
26
1// Create the converter
2converter = new Img2Pdf();
3
4// Create output file
5if (!converter.create(outPath, "", "", NativeLibrary.PERMISSION.ePermNoEncryption))
6 throw new Exception(String.format("Output file %s cannot be created. %s (ErrorCode: 0x%08x).",
7 outPath, converter.getErrorMessage(), converter.getErrorCode()));
8
9// Set info dictionary
10converter.setInfoEntry("Title", "Your Title");
11converter.setInfoEntry("Author", "Your Author");
12converter.setInfoEntry("Creator", "Your Creator");
13converter.setInfoEntry("Subject", "Your Subject");
14converter.setInfoEntry("Producer", "Your Producer");
15
16// Convert pages from input image to PDF
17if (!converter.createPageFromImage(inPath))
18 throw new Exception(String.format("Pages cannot be created from image input %s. %s " +
19 "(ErrorCode: 0x%08x).", inPath, converter.getErrorMessage(), converter.getErrorCode()));
20
21// Close output file
22if (!converter.close())
23 throw new Exception(String.format("Output file %s cannot be closed. %s (ErrorCode: 0x%08x).",
24 outPath, converter.getErrorMessage(), converter.getErrorCode()));
25
Convert Image to linearized PDF
1// Create the converter
2pConverter = Img2PdfCreateObject();
3
4// Set linearization
5Img2PdfSetLinearize(pConverter, true);
6
7// Create output file
8if (!Img2PdfCreate(pConverter, szOutPath, _T(""), _T(""), ePermNoEncryption))
9{
10 _tprintf(_T("Output file %s cannot be created. %s (ErrorCode: 0x%08x).\n"), szOutPath, Img2PdfGetErrorMessage(pConverter), Img2PdfGetErrorCode(pConverter));
11 iReturnValue = 1;
12 goto cleanup;
13}
14
15// Convert pages from input image to PDF
16if (!Img2PdfCreatePageFromImage(pConverter, szInPath))
17{
18 _tprintf(_T("Pages cannot be created from image input %s. %s (ErrorCode: 0x%08x).\n"), szInPath, Img2PdfGetErrorMessage(pConverter), Img2PdfGetErrorCode(pConverter));
19 iReturnValue = 1;
20 goto cleanup;
21}
22
23// Close output file
24if (!Img2PdfClose(pConverter))
25{
26 _tprintf(_T("Output file %s cannot be closed. %s (ErrorCode: 0x%08x).\n"), szOutPath, Img2PdfGetErrorMessage(pConverter), Img2PdfGetErrorCode(pConverter));
27 iReturnValue = 1;
28 goto cleanup;
29}
30
1// Create the converter
2using (Img2Pdf converter = new Img2Pdf())
3{
4 // Set linearization
5 converter.Linearize = true;
6
7 // Create output file
8 if (!converter.Create(outPath, "", "", PDFPermission.ePermNoEncryption))
9 throw new Exception(String.Format("Output file {0} cannot be created. {1} " +
10 "(ErrorCode: 0x{2:x})", outPath, converter.ErrorMessage, converter.ErrorCode));
11
12 // Convert pages from input image to PDF
13 if (!converter.CreatePageFromImage(inPath))
14 throw new Exception(String.Format("Pages cannot be created from image input {0}. {1}" +
15 "(ErrorCode: 0x{2:x})", inPath, converter.ErrorMessage, converter.ErrorCode));
16
17 // Close output file
18 if (!converter.Close())
19 throw new Exception(String.Format("Output file {0} cannot be closed. {1} " +
20 "(ErrorCode: 0x{2:x})", outPath, converter.ErrorMessage, converter.ErrorCode));
21}
22
1// Create the converter
2converter = new Img2Pdf();
3
4// Set linearization
5converter.setLinearize(true);
6
7// Create output file
8if (!converter.create(outPath, "", "", NativeLibrary.PERMISSION.ePermNoEncryption))
9 throw new Exception(String.format("Output file %s cannot be created. %s (ErrorCode: 0x%08x).",
10 outPath, converter.getErrorMessage(), converter.getErrorCode()));
11
12// Convert pages from input image to PDF
13if (!converter.createPageFromImage(inPath))
14 throw new Exception(String.format("Pages cannot be created from image input %s. %s " +
15 "(ErrorCode: 0x%08x).", inPath, converter.getErrorMessage(), converter.getErrorCode()));
16
17// Close output file
18if (!converter.close())
19 throw new Exception(String.format("Output file %s cannot be closed. %s (ErrorCode: 0x%08x).",
20 outPath, converter.getErrorMessage(), converter.getErrorCode()));
21
Convert Image to PDF with a specific page size
1// Create the converter
2pConverter = Img2PdfCreateObject();
3
4// Set page size
5Img2PdfSetPageSize(pConverter, fWidth, fHeight);
6
7// Create output file
8if (!Img2PdfCreate(pConverter, szOutPath, _T(""), _T(""), ePermNoEncryption))
9{
10 _tprintf(_T("Output file %s cannot be created. %s (ErrorCode: 0x%08x).\n"), szOutPath, Img2PdfGetErrorMessage(pConverter), Img2PdfGetErrorCode(pConverter));
11 iReturnValue = 1;
12 goto cleanup;
13}
14
15// Convert pages from input image to PDF
16if (!Img2PdfCreatePageFromImage(pConverter, szInPath))
17{
18 _tprintf(_T("Pages cannot be created from image input %s. %s (ErrorCode: 0x%08x).\n"), szInPath, Img2PdfGetErrorMessage(pConverter), Img2PdfGetErrorCode(pConverter));
19 iReturnValue = 1;
20 goto cleanup;
21}
22
23// Close output file
24if (!Img2PdfClose(pConverter))
25{
26 _tprintf(_T("Output file %s cannot be closed. %s (ErrorCode: 0x%08x).\n"), szOutPath, Img2PdfGetErrorMessage(pConverter), Img2PdfGetErrorCode(pConverter));
27 iReturnValue = 1;
28 goto cleanup;
29}
30
1// Create the converter
2using (Img2Pdf converter = new Img2Pdf())
3{
4 // Set size of output page
5 converter.SetPageSize(width, height);
6
7 // Create output file
8 if (!converter.Create(outPath, "", "", PDFPermission.ePermNoEncryption))
9 throw new Exception(String.Format("Output file {0} cannot be created. {1} " +
10 "(ErrorCode: 0x{2:x})", outPath, converter.ErrorMessage, converter.ErrorCode));
11
12 // Convert pages from input image to PDF
13 if (!converter.CreatePageFromImage(inPath))
14 throw new Exception(String.Format("Pages cannot be created from image input {0}. " +
15 "{1} (ErrorCode: 0x{2:x})", inPath, converter.ErrorMessage, converter.ErrorCode));
16
17 // Close output file
18 if (!converter.Close())
19 throw new Exception(String.Format("Output file {0} cannot be closed. {1} " +
20 "(ErrorCode: 0x{2:x})", outPath, converter.ErrorMessage, converter.ErrorCode));
21}
22
1// Create the converter
2converter = new Img2Pdf();
3
4// Set size of output page
5converter.setPageSize(width, height);
6
7// Create output file
8if (!converter.create(outPath, "", "", NativeLibrary.PERMISSION.ePermNoEncryption))
9 throw new Exception(String.format("Output file %s cannot be created. %s (ErrorCode: 0x%08x).",
10 outPath, converter.getErrorMessage(), converter.getErrorCode()));
11
12// Convert pages from input image to PDF
13if (!converter.createPageFromImage(inPath))
14 throw new Exception(String.format("Pages cannot be created from image input %s. %s " +
15 "(ErrorCode: 0x%08x).", inPath, converter.getErrorMessage(), converter.getErrorCode()));
16
17// Close output file
18if (!converter.close())
19 throw new Exception(String.format("Output file %s cannot be closed. %s (ErrorCode: 0x%08x).",
20 outPath, converter.getErrorMessage(), converter.getErrorCode()));
21
Document Assembly
Merge multiple images to one PDF
1// Create the converter
2pConverter = Img2PdfCreateObject();
3
4// Set page size
5Img2PdfSetPageSize(pConverter, 595.0, 842.0);
6
7// Create output file
8if (!Img2PdfCreate(pConverter, szOutPath, _T(""), _T(""), ePermNoEncryption))
9{
10 _tprintf(_T("Output file %s cannot be created. %s (ErrorCode: 0x%08x).\n"), szOutPath, Img2PdfGetErrorMessage(pConverter), Img2PdfGetErrorCode(pConverter));
11 iReturnValue = 1;
12 goto cleanup;
13}
14
15// Loop through all input files
16for (int i = 0; i < argc - 2; i++)
17{
18 // Convert pages from input image to PDF
19 if (!Img2PdfCreatePageFromImage(pConverter, szInPath[i]))
20 {
21 _tprintf(_T("Pages cannot be created from image input %s. %s (ErrorCode: 0x%08x).\n"), szInPath[i], Img2PdfGetErrorMessage(pConverter), Img2PdfGetErrorCode(pConverter));
22 iReturnValue = 1;
23 goto cleanup;
24 }
25}
26
27// Close output file
28if (!Img2PdfClose(pConverter))
29{
30 _tprintf(_T("Output file %s cannot be closed. %s (ErrorCode: 0x%08x).\n"), szOutPath, Img2PdfGetErrorMessage(pConverter), Img2PdfGetErrorCode(pConverter));
31 iReturnValue = 1;
32 goto cleanup;
33}
34
1// Create the converter
2using (Img2Pdf converter = new Img2Pdf())
3{
4 // Set page size
5 converter.SetPageSize(595, 842);
6
7 // Create output file
8 if (!converter.Create(outPath, "", "", PDFPermission.ePermNoEncryption))
9 throw new Exception(String.Format("Output file {0} cannot be created. {1} " +
10 "(ErrorCode: 0x{2:x})", outPath, converter.ErrorMessage, converter.ErrorCode));
11
12 // Loop through all input files
13 for (int i = 0; i < args.Length - 1; i++)
14 {
15 // Add pages from input image
16 if (!converter.CreatePageFromImage(inPath[i]))
17 throw new Exception(String.Format("Pages cannot be created from image input {0}. {1}" +
18 " (ErrorCode: 0x{2:x})", inPath[i], converter.ErrorMessage, converter.ErrorCode));
19 }
20
21 // Close output file
22 if (!converter.Close())
23 throw new Exception(String.Format("Output file {0} cannot be closed. {1} " +
24 "(ErrorCode: 0x{2:x})", outPath, converter.ErrorMessage, converter.ErrorCode));
25}
26
1// Create the converter
2converter = new Img2Pdf();
3
4// Set page size
5converter.setPageSize(595, 842);
6
7// Create output file
8if (!converter.create(outPath, "", "", NativeLibrary.PERMISSION.ePermNoEncryption))
9 throw new Exception(String.format("Output file %s cannot be created. %s (ErrorCode: 0x%08x).",
10 outPath, converter.getErrorMessage(), converter.getErrorCode()));
11
12// Loop through all input files
13for (int i = 0; i < args.length - 1; i++)
14{
15 // Add pages from input image
16 if (!converter.createPageFromImage(inPath[i]))
17 throw new Exception(String.format("Pages cannot be created from image input %s. %s " +
18 "(ErrorCode: 0x%08x).", inPath[i], converter.getErrorMessage(),
19 converter.getErrorCode()));
20}
21
22// Close output file
23if (!converter.close())
24 throw new Exception(String.format("Output file %s cannot be closed. %s (ErrorCode: 0x%08x).",
25 outPath, converter.getErrorMessage(), converter.getErrorCode()));
26
Split multipage TIFF to single-page PDF
1// Create the converter
2pConverter = Img2PdfCreateObject();
3
4// Create codec for input
5pInCodec = PdfCodecCreateObject();
6
7// Open input image
8if (!PdfCodecOpen(pInCodec, szInPath))
9{
10 _tprintf(_T("Input image %s cannot be opened. %s (ErrorCode: 0x%08x).\n"), szInPath, PdfCodecGetErrorMessageA(pInCodec), PdfCodecGetErrorCode(pInCodec));
11 iReturnValue = 1;
12 goto cleanup;
13}
14
15// Loop over all pages of image file and create each time a new PDF
16for (int iPage = 1; iPage <= PdfCodecGetPageCount(pInCodec); iPage++)
17{
18 PdfCodecSetPageNo(pInCodec, iPage);
19
20 // Change extension
21 _tcscpy(szDocPath, szOutPath);
22 _tcstok(szDocPath, _T("."));
23 _stprintf(szBuffer, "%d", iPage);
24 _tcscat(szDocPath, szBuffer);
25 _tcscat(szDocPath, _T(".pdf"));
26
27 // Create output file
28 if (!Img2PdfCreate(pConverter, szDocPath, _T(""), _T(""), ePermNoEncryption))
29 {
30 _tprintf(_T("Output file %s cannot be created. %s (ErrorCode: 0x%08x).\n"), szOutPath, Img2PdfGetErrorMessage(pConverter), Img2PdfGetErrorCode(pConverter));
31 iReturnValue = 1;
32 goto cleanup;
33 }
34
35 // Create pages from image codec
36 if (!Img2PdfCreatePageFromCodec(pConverter, pInCodec))
37 {
38 _tprintf(_T("Page %d of the image could not be converted to PDF %s. %s (ErrorCode: 0x%08x).\n"), iPage, szOutPath, Img2PdfGetErrorMessage(pConverter), Img2PdfGetErrorCode(pConverter));
39 iReturnValue = 1;
40 goto cleanup;
41 }
42}
43// Close output file
44if (!Img2PdfClose(pConverter))
45{
46 _tprintf(_T("Output file %s cannot be closed. %s (ErrorCode: 0x%08x).\n"), szOutPath, Img2PdfGetErrorMessage(pConverter), Img2PdfGetErrorCode(pConverter));
47 iReturnValue = 1;
48 goto cleanup;
49}
50
1// Create the converter
2using (Img2Pdf converter = new Img2Pdf())
3{
4 // Create codec for input
5 using (PdfCodec inCodec = new PdfCodec())
6 {
7 // Open input image
8 if (!inCodec.Open(inPath))
9 throw new Exception(String.Format("Input image {0} cannot be opened. {1} " +
10 "(ErrorCode: 0x{2:x})", inPath, inCodec.ErrorMessage, inCodec.ErrorCode));
11
12 // Loop over all pages of image file and create each time a new PDF
13 for (int iPage = 1; iPage <= inCodec.PageCount; iPage++)
14 {
15 inCodec.PageNo = iPage;
16
17 string docPath = Path.Combine(Path.GetDirectoryName(outPath),
18 Path.ChangeExtension(Path.GetFileNameWithoutExtension(outPath) + iPage.ToString(),
19 "pdf"));
20
21 // Create output file
22 if (!converter.Create(docPath, "", "", PDFPermission.ePermNoEncryption))
23 throw new Exception(String.Format("Output file {0} cannot be created. {1} " +
24 "(ErrorCode: 0x{2:x})", outPath, converter.ErrorMessage, converter.ErrorCode));
25
26 // Create pages from image codec
27 if (!converter.CreatePageFromCodec(inCodec))
28 throw new Exception(String.Format("Page {0} of the image could not be converted " +
29 "to PDF {1}. {2} (ErrorCode: 0x{3:x})", iPage, outPath, converter.ErrorMessage,
30 converter.ErrorCode));
31 }
32 // Close output file
33 if (!converter.Close())
34 throw new Exception(String.Format("Output file {0} cannot be closed. {1} " +
35 "(ErrorCode: 0x{2:x})", outPath, converter.ErrorMessage, converter.ErrorCode));
36 }
37}
38
1// Create the converter
2converter = new Img2Pdf();
3
4// Create codec for input
5inCodec = new Codec();
6
7// Open input image
8if (!inCodec.open(inPath))
9 throw new Exception(String.format("Input image %s cannot be opened. %s (ErrorCode: 0x%08x).",
10 inPath, inCodec.getErrorMessage(), inCodec.getErrorCode()));
11
12// Loop over all pages of image file and create each time a new PDF
13for (int iPage = 1; iPage <= inCodec.getPageCount(); iPage++)
14{
15 inCodec.setPageNo(iPage);
16
17 File file = new File(outPath);
18 String docPath = file.getName();
19
20 docPath = docPath.substring(0, docPath.lastIndexOf(".")) + iPage + ".pdf";
21
22 // Create output file
23 if (!converter.create(docPath, "", "", NativeLibrary.PERMISSION.ePermNoEncryption))
24 throw new Exception(String.format("Output file %s cannot be created. %s " +
25 "(ErrorCode: 0x%08x).", outPath, converter.getErrorMessage(),
26 converter.getErrorCode()));
27
28 // Create pages from image codec
29 if (!converter.createPageFromCodec(inCodec))
30 throw new Exception(String.format("Page %d of the image could not be converted to " +
31 "PDF %s. %s (ErrorCode: 0x%08x).", iPage, outPath, converter.getErrorMessage(),
32 converter.getErrorCode()));
33}
34// Close output file
35if (!converter.close())
36 throw new Exception(String.format("Output file %s cannot be closed. %s (ErrorCode: 0x%08x).",
37 outPath, converter.getErrorMessage(), converter.getErrorCode()));
38
In Memory
Create PDF from Image in memory
1// Create the converter
2pConverter = Img2PdfCreateObject();
3
4// Create PDF in memory
5if (!Img2PdfCreateInMemory(pConverter))
6{
7 _tprintf(_T("Codec cannot be opened. %s (ErrorCode: 0x%08x).\n"), Img2PdfGetErrorMessage(pConverter), Img2PdfGetErrorCode(pConverter));
8 iReturnValue = 1;
9 goto cleanup;
10}
11
12// Create codec for input
13pInCodec = PdfCodecCreateObject();
14
15// Open image from memory
16if (!PdfCodecOpenMem(pInCodec, pInBuffer, nLength))
17{
18 _tprintf(_T("Codec cannot be opened. %s (ErrorCode: 0x%08x).\n"), PdfCodecGetErrorMessageA(pInCodec), PdfCodecGetErrorCode(pInCodec));
19 iReturnValue = 1;
20 goto cleanup;
21}
22
23// Convert all pages
24for (int iPage = 1; iPage <= PdfCodecGetPageCount(pInCodec); iPage++)
25{
26 PdfCodecSetPageNo(pInCodec, iPage);
27
28 // Create pages from image codec
29 if (!Img2PdfCreatePageFromCodec(pConverter, pInCodec))
30 {
31 _tprintf(_T("Page %d of the image could not be converted to PDF %s. %s (ErrorCode: 0x%08x).\n"), iPage, szOutImage, Img2PdfGetErrorMessage(pConverter), Img2PdfGetErrorCode(pConverter));
32 }
33}
34// Close output file
35if (!Img2PdfClose(pConverter))
36{
37 _tprintf(_T("Output file %s cannot be closed. %s (ErrorCode: 0x%08x).\n"), szOutImage, Img2PdfGetErrorMessage(pConverter), Img2PdfGetErrorCode(pConverter));
38 iReturnValue = 1;
39 goto cleanup;
40}
41
42// Get PDF in buffer
43TPDFByteArray* pOutBuffer = Img2PdfGetPdf(pConverter);
44
45if ((pData = _tfopen(szOutImage, _T("wb"))) == NULL)
46{
47 _tprintf(_T("Getting buffer of output PDF failed. %s (ErrorCode: 0x%08x).\n"), Img2PdfGetErrorMessage(pConverter), Img2PdfGetErrorCode(pConverter));
48 iReturnValue = 1;
49 goto cleanup;
50}
51
52// Write bytes to output file
53fwrite(pOutBuffer->m_pData, pOutBuffer->m_nLength, 1, pData);
54fclose(pData);
55
1// Create the converter
2using (Img2Pdf converter = new Img2Pdf())
3{
4 // Create PDF in memory
5 if (!converter.CreateInMemory())
6 throw new Exception(String.Format("Output file {0} cannot be created. {1} " +
7 "(ErrorCode: 0x{2:x})", outImage, converter.ErrorMessage, converter.ErrorCode));
8
9 // Create codec for input
10 using (PdfCodec inCodec = new PdfCodec())
11 {
12 // Open image from memory
13 if (!inCodec.OpenMem(inBuffer))
14 throw new Exception(String.Format("Codec cannot be opened. {0} (ErrorCode: 0x{1:x})",
15 inCodec.ErrorMessage, inCodec.ErrorCode));
16
17 // Convert all pages
18 for (int iPage = 1; iPage <= inCodec.PageCount; iPage++)
19 {
20 inCodec.PageNo = iPage;
21
22 // Create pages from image codec
23 if (!converter.CreatePageFromCodec(inCodec))
24 throw new Exception(String.Format("Page {0} of the image could not be converted" +
25 " to PDF {1}. {2} (ErrorCode: 0x{3:x}) ", iPage, outImage,
26 converter.ErrorMessage, converter.ErrorCode));
27 }
28 // Close output file
29 if (!converter.Close())
30 throw new Exception(String.Format("Output file {0} cannot be closed. {1} " +
31 "(ErrorCode: 0x{2:x})", outImage, converter.ErrorMessage, converter.ErrorCode));
32 }
33
34 // Get PDF in buffer
35 outBuffer = converter.GetPdf();
36 if (outBuffer == null)
37 throw new Exception(String.Format("Getting buffer of output PDF failed. {0} " +
38 "(ErrorCode: 0x{1:x})", converter.ErrorMessage, converter.ErrorCode));
39
40 // Write bytes to output file
41 File.WriteAllBytes(outImage, outBuffer);
42}
43
1// Create the converter
2converter = new Img2Pdf();
3
4// Create PDF in memory
5if (!converter.createInMemory())
6 throw new Exception(String.format("Output file %s cannot be created in memory. %s" +
7 "(ErrorCode: 0x%08x).", outPath, converter.getErrorMessage(), converter.getErrorCode()));
8
9// Create codec for input
10inCodec = new Codec();
11
12// Open image from memory
13if (!inCodec.openMem(inBuffer))
14 throw new Exception(String.format("Input cannot be opened from memory. %s (ErrorCode: 0x%08x).",
15 inCodec.getErrorMessage(), inCodec.getErrorCode()));
16
17// Convert all pages
18for (int iPage = 1; iPage <= inCodec.getPageCount(); iPage++)
19{
20 inCodec.setPageNo(iPage);
21
22 // Create pages from image codec
23 if (!converter.createPageFromCodec(inCodec))
24 throw new Exception(String.format("Page %d of the image could not be converted to PDF " +
25 "%s. %s (ErrorCode: 0x%08x).", iPage, outPath, converter.getErrorMessage(),
26 converter.getErrorCode()));
27}
28// Close output file
29if (!converter.close())
30 throw new Exception(String.format("Output file %s cannot be closed. %s (ErrorCode: 0x%08x).",
31 outPath, converter.getErrorMessage(), converter.getErrorCode()));
32
33// Get PDF in buffer
34outBuffer = converter.getPdf();
35if (outBuffer == null)
36 throw new Exception(String.format("Getting buffer of output PDF failed. %s " +
37 "(ErrorCode: 0x%08x).", converter.getErrorMessage(), converter.getErrorCode()));
38
39// Write bytes to output file
40Files.write(Paths.get(outPath), outBuffer, StandardOpenOption.CREATE_NEW);
41
Image to Image Assembly
Merge multipage Images to TIFF
1// Create codec for output
2pOutCodec = PdfCodecCreateObject();
3
4// Create output file
5if (!PdfCodecCreate(pOutCodec, szOutImage))
6{
7 _tprintf(_T("Output file %s cannot be created. %s (ErrorCode: 0x%08x).\n"), szOutImage, PdfCodecGetErrorMessageA(pOutCodec), PdfCodecGetErrorCode(pOutCodec));
8 iReturnValue = 1;
9 goto cleanup;
10}
11
12// Create image copier
13pCopier = Img2ImgCreateObject();
14
15// Loop through all input files
16for (int i = 0; i < argc - 2; i++)
17{
18 // Create codec for input
19 pInCodec = PdfCodecCreateObject();
20
21 // Open input image
22 if (!PdfCodecOpen(pInCodec, szInImage[i]))
23 {
24 _tprintf(_T("Input file %s cannot be opened. %s (ErrorCode: 0x%08x).\n"), szInImage[i], PdfCodecGetErrorMessageA(pInCodec), PdfCodecGetErrorCode(pInCodec));
25 iReturnValue = 1;
26 goto cleanup;
27 }
28
29 // Convert all pages
30 for (int iPage = 1; iPage <= PdfCodecGetPageCount(pInCodec); iPage++)
31 {
32 PdfCodecSetPageNo(pInCodec, iPage);
33
34 // Copy page from input to output
35 if (!Img2ImgCopyPage(pCopier, pInCodec, pOutCodec))
36 {
37 _tprintf(_T("Input cannot be copied to output. %s (ErrorCode: 0x%08x).\n"), Img2ImgGetErrorMessageA(pCopier), Img2ImgGetErrorCode(pCopier));
38 iReturnValue = 1;
39 goto cleanup;
40 }
41 }
42}
43
1// Create codec for output
2using (PdfCodec outCodec = new PdfCodec())
3{
4 // Create output file
5 if (!outCodec.Create(outImage))
6 throw new Exception(String.Format("Output file {0} cannot be created. {1}" +
7 "(ErrorCode: 0x{2:x})", outImage, outCodec.ErrorMessage, outCodec.ErrorCode));
8
9 // Create image copier
10 using (Img2Img copier = new Img2Img())
11 {
12 // Loop through all input files
13 for (int i = 0; i < args.Length - 1; i++)
14 {
15 // Create codec for input
16 using (PdfCodec inCodec = new PdfCodec())
17 {
18 // Open input image
19 if (!inCodec.Open(inImage[i]))
20 throw new Exception(String.Format("Input image {0} cannot be opened. {1} " +
21 "(ErrorCode: 0x{2:x})", inImage, inCodec.ErrorMessage, inCodec.ErrorCode));
22
23 // Convert all pages
24 for (int iPage = 1; iPage <= inCodec.PageCount; iPage++)
25 {
26 inCodec.PageNo = iPage;
27
28 // Copy page from input to output
29 if (!copier.CopyPage(inCodec, outCodec))
30 throw new Exception(String.Format("Input cannot be copied to output. " +
31 "{0} (ErrorCode: 0x{1:x}", copier.ErrorMessage, copier.ErrorCode));
32 }
33 }
34 }
35 }
36}
37
1// Create codec for output
2outCodec = new Codec();
3
4// Create output file
5if (!outCodec.create(outImage))
6 throw new Exception(String.format("Output file %s cannot be created. %s (ErrorCode: 0x%08x).",
7 outImage, outCodec.getErrorMessage(), outCodec.getErrorCode()));
8
9// Create image copier
10copier = new Img2Img();
11
12// Loop through all input files
13for (int i = 0; i < args.length - 1; i++)
14{
15 // Create codec for input
16 inCodec = new Codec();
17
18 // Open input image
19 if (!inCodec.open(inImage[i]))
20 throw new Exception(String.format("Input image %s cannot be opened. %s " +
21 "(ErrorCode: 0x%08x).", inImage, inCodec.getErrorMessage(), inCodec.getErrorCode()));
22
23 // Convert all pages
24 for (int iPage = 1; iPage <= inCodec.getPageCount(); iPage++)
25 {
26 inCodec.setPageNo(iPage);
27
28 // Copy page from input to output
29 if (!copier.copyPage(inCodec, outCodec))
30 throw new Exception(String.format("Input %s cannot be copied to output. %s " +
31 "(ErrorCode: 0x%08x).", inImage, copier.getErrorMessage(), copier.getErrorCode()));
32 }
33}
34
Split multipage TIFF to single-page Images
1// Create codec for input
2pInCodec = PdfCodecCreateObject();
3
4// Open image file
5if (!PdfCodecOpen(pInCodec, szInImage))
6{
7 _tprintf(_T("Image file %s cannot be opened. %s (ErrorCode: 0x%08x).\n"), szInImage, PdfCodecGetErrorMessageA(pInCodec), PdfCodecGetErrorCode(pInCodec));
8 iReturnValue = 1;
9 goto cleanup;
10}
11
12// Loop over all pages of image file and create each time a new image file
13for (int iPage = 1; iPage <= PdfCodecGetPageCount(pInCodec); iPage++)
14{
15 PdfCodecSetPageNo(pInCodec, iPage);
16
17 // Change extension
18 _tcscpy(szImagePath, szOutImage);
19 _tcstok(szImagePath, _T("."));
20 _stprintf(szBuffer, "%d", iPage);
21 _tcscat(szImagePath, szBuffer);
22 _tcscat(szImagePath, szExt);
23
24 // Create image copier
25 pCopier = Img2ImgCreateObject();
26
27 // Convert present image to separate single-page image
28 if (!Img2ImgConvertFile(pCopier, szInImage, szImagePath, iPage, iPage))
29 {
30 _tprintf(_T("Page %d of the image file cannot be converted. %s (ErrorCode: 0x%08x).\n"), iPage, Img2ImgGetErrorMessageA(pCopier), Img2ImgGetErrorCode(pCopier));
31 iReturnValue = 1;
32 goto cleanup;
33 }
34}
35
1// Create codec for input
2using (PdfCodec inCodec = new PdfCodec())
3{
4 // Open image file
5 if (!inCodec.Open(inImage))
6 throw new Exception(String.Format("Image file {0} cannot be opened. {1} " +
7 "(ErrorCode: 0x{2:x})", inImage, inCodec.ErrorMessage, inCodec.ErrorCode));
8
9 // Loop over all pages of image file and create each time a new image file
10 for (int iPage = 1; iPage <= inCodec.PageCount; iPage++)
11 {
12 inCodec.PageNo = iPage;
13
14 string imagePath = Path.Combine(Path.GetDirectoryName(outImage),
15 Path.ChangeExtension(Path.GetFileNameWithoutExtension(outImage) + iPage.ToString(),
16 extension));
17
18 // Create image copier
19 using (Img2Img copier = new Img2Img())
20 {
21 // Convert present image to separate single-page image
22 if (!copier.ConvertFile(inImage, imagePath, iPage, iPage))
23 throw new Exception(String.Format("Page {0} of the image file cannot be " +
24 "converted. {1} (ErrorCode: 0x{2:x})", iPage, copier.ErrorMessage,
25 copier.ErrorCode));
26 }
27 }
28}
29
1// Create codec for input
2inCodec = new Codec();
3
4// Open image file
5if (!inCodec.open(inImage))
6 throw new Exception(String.format("Input image %s cannot be opened. %s (ErrorCode: 0x%08x).",
7 inImage, inCodec.getErrorMessage(), inCodec.getErrorCode()));
8
9// Loop over all pages of image file and create each time a new image file
10for (int iPage = 1; iPage <= inCodec.getPageCount(); iPage++)
11{
12 inCodec.setPageNo(iPage);
13
14 String imagePath = file.getName();
15
16 imagePath = imagePath.substring(0, imagePath.lastIndexOf(".")) + iPage + extension;
17
18 // Create image copier
19 copier = new Img2Img();
20
21 // Convert present image to separate single-page image
22 if (!copier.convertFile(inImage, imagePath, iPage, iPage))
23 throw new Exception(String.format("Page %d of the image file cannot be converted. %s " +
24 "(ErrorCode: 0x%08x).", iPage, copier.getErrorMessage(), copier.getErrorCode()));
25}
26
Image to Image Conversion
Convert Image to Image and set compression and quality
1// Create codec for input
2pInCodec = PdfCodecCreateObject();
3
4// Open input image
5if (!PdfCodecOpen(pInCodec, szInImage))
6{
7 _tprintf(_T("Input file %s cannot be opened. %s (ErrorCode: 0x%08x).\n"), szInImage, PdfCodecGetErrorMessageA(pInCodec), PdfCodecGetErrorCode(pInCodec));
8 iReturnValue = 1;
9 goto cleanup;
10}
11
12// Create codec for output
13pOutCodec = PdfCodecCreateObject();
14
15// Create output file
16if (!PdfCodecCreate(pOutCodec, szOutImage))
17{
18 _tprintf(_T("Output file %s cannot be created. %s (ErrorCode: 0x%08x).\n"), szOutImage, PdfCodecGetErrorMessageA(pOutCodec), PdfCodecGetErrorCode(pOutCodec));
19 iReturnValue = 1;
20 goto cleanup;
21}
22
23// Create image copier
24pCopier = Img2ImgCreateObject();
25
26// Set continuous compression
27Img2ImgSetContinuousCompression(pCopier, eCompression);
28
29// Set quality
30Img2ImgSetImageQuality(pCopier, iQuality);
31
32// Loop through all pages of input
33for (int iPage = 1; iPage <= PdfCodecGetPageCount(pInCodec); iPage++)
34{
35 PdfCodecSetPageNo(pInCodec, iPage);
36
37 // Copy all pages from input to output
38 if (!Img2ImgCopyPage(pCopier, pInCodec, pOutCodec))
39 {
40 _tprintf(_T("Input file %s cannot be copied to output. %s (ErrorCode: 0x%08x).\n"), szInImage, Img2ImgGetErrorMessageA(pCopier), Img2ImgGetErrorCode(pCopier));
41 iReturnValue = 1;
42 goto cleanup;
43 }
44}
45
1// Create codec for input
2using (PdfCodec inCodec = new PdfCodec())
3{
4 // Open input image
5 if (!inCodec.Open(inImage))
6 throw new Exception(String.Format("Input file {0} cannot be opened. {1} " +
7 "(ErrorCode: 0x{2:x})", inImage, inCodec.ErrorMessage, inCodec.ErrorCode));
8
9 // Create codec for output
10 using (PdfCodec outCodec = new PdfCodec())
11 {
12 // Create output file
13 if (!outCodec.Create(outImage))
14 throw new Exception(String.Format("Output file {0} cannot be created. " +
15 "{1} (ErrorCode: 0x{2:x})", outImage, outCodec.ErrorMessage, outCodec.ErrorCode));
16
17 // Create image copier
18 using (Img2Img copier = new Img2Img())
19 {
20 // Set continuous compression
21 copier.ContinuousCompression = compression;
22
23 // Set quality
24 copier.ImageQuality = quality;
25
26 // Loop through all pages of input
27 for (int iPage = 1; iPage <= inCodec.PageCount; iPage++)
28 {
29 inCodec.PageNo = iPage;
30
31 // Copy all pages from input to output
32 if (!copier.CopyPage(inCodec, outCodec))
33 throw new Exception(String.Format("Input {0} cannot be copied to output. {1}" +
34 " (ErrorCode: 0x{2:x})", inImage, copier.ErrorMessage, copier.ErrorCode));
35 }
36 }
37 }
38}
39
1// Create codec for input
2inCodec = new Codec();
3
4// Open input image
5if (!inCodec.open(inImage))
6 throw new Exception(String.format("Input file %s cannot be opened. %s (ErrorCode: 0x%08x).",
7 inImage, inCodec.getErrorMessage(), inCodec.getErrorCode()));
8
9// Create codec for output
10outCodec = new Codec();
11
12// Create output file
13if (!outCodec.create(outImage))
14 throw new Exception(String.format("Output file %s cannot be created. %s (ErrorCode: 0x%08x).",
15 outImage, outCodec.getErrorMessage(), outCodec.getErrorCode()));
16
17// Create image copier
18copier = new Img2Img();
19
20// Set continuous compression
21copier.setContinuousCompression(compression);
22
23// Set quality
24copier.setImageQuality(quality);
25
26// Loop through all pages of input
27for (int iPage = 1; iPage <= inCodec.getPageCount(); iPage++)
28{
29 inCodec.setPageNo(iPage);
30
31 // Copy all pages from input to output
32 if (!copier.copyPage(inCodec, outCodec))
33 throw new Exception(String.format("Input %s cannot be copied to output. %s " +
34 "(ErrorCode: 0x%08x).", inImage, copier.getErrorMessage(), copier.getErrorCode()));
35}
36
Convert Image to Image with specific dimensions
1// Create codec for input
2pInCodec = PdfCodecCreateObject();
3
4// Open input image
5if (!PdfCodecOpen(pInCodec, szInImage))
6{
7 _tprintf(_T("Input file %s cannot be opened. %s (ErrorCode: 0x%08x).\n"), szInImage, PdfCodecGetErrorMessageA(pInCodec), PdfCodecGetErrorCode(pInCodec));
8 iReturnValue = 1;
9 goto cleanup;
10}
11
12// Create codec for output
13pOutCodec = PdfCodecCreateObject();
14
15// Create output file
16if (!PdfCodecCreate(pOutCodec, szOutImage))
17{
18 _tprintf(_T("Output file %s cannot be created. %s (ErrorCode: 0x%08x).\n"), szOutImage, PdfCodecGetErrorMessageA(pOutCodec), PdfCodecGetErrorCode(pOutCodec));
19 iReturnValue = 1;
20 goto cleanup;
21}
22
23// Create image copier
24pCopier = Img2ImgCreateObject();
25
26// Set width and resolution
27Img2ImgSetWidth(pCopier, iWidth);
28Img2ImgSetDPI(pCopier, fResolution);
29
30// Set resampling
31Img2ImgGetAllowResampling(pCopier);
32
33// Loop through all pages of input
34for (int iPage = 1; iPage <= PdfCodecGetPageCount(pInCodec); iPage++)
35{
36 PdfCodecSetPageNo(pInCodec, iPage);
37
38 // Copy all pages from input to output
39 if (!Img2ImgCopyPage(pCopier, pInCodec, pOutCodec))
40 {
41 _tprintf(_T("Input file %s cannot be copied to output. %s (ErrorCode: 0x%08x).\n"), szInImage, Img2ImgGetErrorMessageA(pCopier), Img2ImgGetErrorCode(pCopier));
42 iReturnValue = 1;
43 goto cleanup;
44 }
45}
46
1// Create codec for input
2using (PdfCodec inCodec = new PdfCodec())
3{
4 // Open input image
5 if (!inCodec.Open(inImage))
6 throw new Exception(String.Format("Input file {0} cannot be opened. {1} " +
7 "(ErrorCode: 0x{2:x})", inImage, inCodec.ErrorMessage, inCodec.ErrorCode));
8
9 // Create codec for output
10 using (PdfCodec outCodec = new PdfCodec())
11 {
12 // Create output file
13 if (!outCodec.Create(outImage))
14 throw new Exception(String.Format("Output file {0} cannot be created. " +
15 "{1} (ErrorCode: 0x{2:x})", outImage, outCodec.ErrorMessage, outCodec.ErrorCode));
16
17 // Create image copier
18 using (Img2Img copier = new Img2Img())
19 {
20 // Set width and resolution
21 copier.Width = width;
22 copier.DPI = resolution;
23
24 // Set resampling
25 copier.AllowResampling = true;
26
27 // Loop through all pages of input
28 for (int iPage = 1; iPage <= inCodec.PageCount; iPage++)
29 {
30 inCodec.PageNo = iPage;
31
32 // Copy all pages from input to output
33 if (!copier.CopyPage(inCodec, outCodec))
34 throw new Exception(String.Format("Input {0} cannot be copied to output. {1}" +
35 " (ErrorCode: 0x{2:x})", inImage, copier.ErrorMessage, copier.ErrorCode));
36 }
37 }
38 }
39}
40
1// Create codec for input
2inCodec = new Codec();
3
4// Open input image
5if (!inCodec.open(inImage))
6 throw new Exception(String.format("Input file %s cannot be opened. %s (ErrorCode: 0x%08x).",
7 inImage, inCodec.getErrorMessage(), inCodec.getErrorCode()));
8
9// Create codec for output
10outCodec = new Codec();
11
12// Create output file
13if (!outCodec.create(outImage))
14 throw new Exception(String.format("Output file %s cannot be created. %s (ErrorCode: 0x%08x).",
15 outImage, outCodec.getErrorMessage(), outCodec.getErrorCode()));
16
17// Create image copier
18copier = new Img2Img();
19
20// Set width and resolution
21copier.setWidth(width);
22copier.setDPI(resolution);
23
24// Set resampling
25copier.setAllowResampling(true);
26
27// Loop through all pages of input
28for (int iPage = 1; iPage <= inCodec.getPageCount(); iPage++)
29{
30 inCodec.setPageNo(iPage);
31
32 // Copy all pages from input to output
33 if (!copier.copyPage(inCodec, outCodec))
34 throw new Exception(String.format("Input %s cannot be copied to output. %s " +
35 "(ErrorCode: 0x%08x).", inImage, copier.getErrorMessage(), copier.getErrorCode()));
36}
37