Aperçu d'exemples
Conversion
C# sample:
// Create the converter
using (Img2Pdf converter = new Img2Pdf())
{
// Create output file
if (!converter.Create(outPath, "", "", PDFPermission.ePermNoEncryption))
throw new Exception(String.Format("Output file {0} cannot be created. {1} " +
"(ErrorCode: 0x{2:x})", outPath, converter.ErrorMessage, converter.ErrorCode));
// Set xmp metadata
converter.SetMetadata(metaFile);
// Convert pages from input image to PDF
if (!converter.CreatePageFromImage(inPath))
throw new Exception(String.Format("Pages cannot be created from image input {0}. " +
"{1} (ErrorCode: 0x{2:x})", inPath, converter.ErrorMessage, converter.ErrorCode));
// Close output file
if (!converter.Close())
throw new Exception(String.Format("Output file {0} cannot be closed. " +
"{1} (ErrorCode: 0x{2:x})", outPath, converter.ErrorMessage, converter.ErrorCode));
}
C# sample:
Java sample:
// Create the converter
converter = new Img2Pdf();
// Create output file
if (!converter.create(outPath, "", "", NativeLibrary.PERMISSION.ePermNoEncryption))
throw new Exception(String.format("Output file %s cannot be created. %s (ErrorCode: 0x%08x).",
outPath, converter.getErrorMessage(), converter.getErrorCode()));
// Set xmp metadata
converter.setMetadata(metaFile);
// Convert pages from input image to PDF
if (!converter.createPageFromImage(inPath))
throw new Exception(String.format("Pages cannot be created from image input %s. %s " +
"(ErrorCode: 0x%08x).", inPath, converter.getErrorMessage(), converter.getErrorCode()));
// Close output file
if (!converter.close())
throw new Exception(String.format("Output file %s cannot be closed. %s (ErrorCode: 0x%08x).",
outPath, converter.getErrorMessage(), converter.getErrorCode()));
Java sample:
C sample:
// Create the converter
pConverter = Img2PdfCreateObject();
// Create output file
if (!Img2PdfCreate(pConverter, szOutPath, _T(""), _T(""), ePermNoEncryption))
{
_tprintf(_T("Output file %s cannot be created. %s (ErrorCode: 0x%08x).\n"), szOutPath, Img2PdfGetErrorMessage(pConverter), Img2PdfGetErrorCode(pConverter));
iReturnValue = 1;
goto cleanup;
}
// Set xmp metadata
Img2PdfSetMetadata(pConverter, szMetaFile);
// Convert pages from input image to PDF
if (!Img2PdfCreatePageFromImage(pConverter, szInPath))
{
_tprintf(_T("Pages cannot be created from image input %s. %s (ErrorCode: 0x%08x).\n"), szInPath, Img2PdfGetErrorMessage(pConverter), Img2PdfGetErrorCode(pConverter));
iReturnValue = 1;
goto cleanup;
}
// Close output file
if (!Img2PdfClose(pConverter))
{
_tprintf(_T("Output file %s cannot be closed. %s (ErrorCode: 0x%08x).\n"), szOutPath, Img2PdfGetErrorMessage(pConverter), Img2PdfGetErrorCode(pConverter));
iReturnValue = 1;
goto cleanup;
}
C sample:
C# sample:
// Create the converter
using (Img2Pdf converter = new Img2Pdf())
{
// Create output file
if (!converter.Create(outPath, "", "", PDFPermission.ePermNoEncryption))
throw new Exception(String.Format("Output file {0} cannot be created. {1}" +
"(ErrorCode: 0x{2:x})", outPath, converter.ErrorMessage, converter.ErrorCode));
// Set compression
converter.ContinuousCompression = compression;
// Set image quality
converter.ImageQuality = quality;
// Convert pages from input image to PDF
if (!converter.CreatePageFromImage(inPath))
throw new Exception(String.Format("Pages cannot be created from image input {0}. " +
"{1} (ErrorCode: 0x{2:x})", inPath, converter.ErrorMessage, converter.ErrorCode));
// Close output file
if (!converter.Close())
throw new Exception(String.Format("Output file {0} cannot be closed. {1}" +
"(ErrorCode: 0x{2:x})", outPath, converter.ErrorMessage, converter.ErrorCode));
}
C# sample:
Java sample:
// Create the converter
converter = new Img2Pdf();
// Create output file
if (!converter.create(outPath, "", "", NativeLibrary.PERMISSION.ePermNoEncryption))
throw new Exception(String.format("Output file %s cannot be created. %s (ErrorCode: 0x%08x).",
outPath, converter.getErrorMessage(), converter.getErrorCode()));
// Set compression
converter.setContinuousCompression(compression);
// Set image quality
converter.setImageQuality(quality);
// Convert pages from input image to PDF
if (!converter.createPageFromImage(inPath))
throw new Exception(String.format("Pages cannot be created from image input %s. %s " +
"(ErrorCode: 0x%08x).", inPath, converter.getErrorMessage(), converter.getErrorCode()));
// Close output file
if (!converter.close())
throw new Exception(String.format("Output file %s cannot be closed. %s (ErrorCode: 0x%08x).",
outPath, converter.getErrorMessage(), converter.getErrorCode()));
Java sample:
C sample:
// Create the converter
pConverter = Img2PdfCreateObject();
// Create output file
if (!Img2PdfCreate(pConverter, szOutPath, _T(""), _T(""), ePermNoEncryption))
{
_tprintf(_T("Output file %s cannot be created. %s (ErrorCode: 0x%08x).\n"), szOutPath, Img2PdfGetErrorMessage(pConverter), Img2PdfGetErrorCode(pConverter));
iReturnValue = 1;
goto cleanup;
}
// Set compression
Img2PdfSetContinuousCompression(pConverter, eCompression);
// Set image quality
Img2PdfSetImageQuality(pConverter, iQuality);
// Convert pages from input image to PDF
if (!Img2PdfCreatePageFromImage(pConverter, szInPath))
{
_tprintf(_T("Pages cannot be created from image input %s. %s (ErrorCode: 0x%08x).\n"), szInPath, Img2PdfGetErrorMessage(pConverter), Img2PdfGetErrorCode(pConverter));
iReturnValue = 1;
goto cleanup;
}
// Close output file
if (!Img2PdfClose(pConverter))
{
_tprintf(_T("Output file %s cannot be closed. %s (ErrorCode: 0x%08x).\n"), szOutPath, Img2PdfGetErrorMessage(pConverter), Img2PdfGetErrorCode(pConverter));
iReturnValue = 1;
goto cleanup;
}
C sample:
C# sample:
// Create the converter
using (Img2Pdf converter = new Img2Pdf())
{
// Set PDF Compliance level
converter.Compliance = compliance;
// Create output file
if (!converter.Create(outPath, "", "", PDFPermission.ePermNoEncryption))
throw new Exception(String.Format("Output file {0} cannot be created. {1} "+
"(ErrorCode: 0x{2:x})", outPath, converter.ErrorMessage, converter.ErrorCode));
// Convert pages from input image to PDF
if (!converter.CreatePageFromImage(inPath))
throw new Exception(String.Format("Pages cannot be created from image input {0}. " +
"{1} (ErrorCode: 0x{2:x})", inPath, converter.ErrorMessage, converter.ErrorCode));
// Close output file
if (!converter.Close())
throw new Exception(String.Format("Output file {0} cannot be closed. " +
"{1} (ErrorCode: 0x{2:x})", outPath, converter.ErrorMessage, converter.ErrorCode));
}
C# sample:
Java sample:
// Create the converter
converter = new Img2Pdf();
// Set PDF Compliance level
converter.setCompliance(compliance);
// Create output file
if (!converter.create(outPath, "", "", NativeLibrary.PERMISSION.ePermNoEncryption))
throw new Exception(String.format("Output file %s cannot be created. %s (ErrorCode: 0x%08x).",
outPath, converter.getErrorMessage(), converter.getErrorCode()));
// Convert pages from input image to PDF
if (!converter.createPageFromImage(inPath))
throw new Exception(String.format("Pages cannot be created from image input %s. %s " +
"(ErrorCode: 0x%08x).", inPath, converter.getErrorMessage(), converter.getErrorCode()));
// Close output file
if (!converter.close())
throw new Exception(String.format("Output file %s cannot be closed. %s (ErrorCode: 0x%08x).",
outPath, converter.getErrorMessage(), converter.getErrorCode()));
Java sample:
C sample:
// Create the converter
pConverter = Img2PdfCreateObject();
// Set PDF Compliance level
Img2PdfSetCompliance(pConverter, eCompliance);
// Create output file
if (!Img2PdfCreate(pConverter, szOutPath, _T(""), _T(""), ePermNoEncryption))
{
_tprintf(_T("Output file %s cannot be created. %s (ErrorCode: 0x%08x).\n"), szOutPath, Img2PdfGetErrorMessage(pConverter), Img2PdfGetErrorCode(pConverter));
iReturnValue = 1;
goto cleanup;
}
// Convert pages from input image to PDF
if (!Img2PdfCreatePageFromImage(pConverter, szInPath))
{
_tprintf(_T("Pages cannot be created from image input %s. %s (ErrorCode: 0x%08x).\n"), szInPath, Img2PdfGetErrorMessage(pConverter), Img2PdfGetErrorCode(pConverter));
iReturnValue = 1;
goto cleanup;
}
// Close output file
if (!Img2PdfClose(pConverter))
{
_tprintf(_T("Output file %s cannot be closed. %s (ErrorCode: 0x%08x).\n"), szOutPath, Img2PdfGetErrorMessage(pConverter), Img2PdfGetErrorCode(pConverter));
iReturnValue = 1;
goto cleanup;
}
C sample:
C# sample:
// Create the converter
using (Img2Pdf converter = new Img2Pdf())
{
// Create encrypted output file
if (!converter.Create(outPath, userPW, ownerPW, PDFPermission.ePermDigitalPrint |
PDFPermission.ePermPrint))
throw new Exception(String.Format("Output file {0} cannot be created. {1} " +
"(ErrorCode: 0x{2:x})", outPath, converter.ErrorMessage, converter.ErrorCode));
// Convert pages from input image to PDF
if (!converter.CreatePageFromImage(inPath))
throw new Exception(String.Format("Pages cannot be created from image input {0}. " +
"{1} (ErrorCode: 0x{2:x})", inPath, converter.ErrorMessage, converter.ErrorCode));
// Close output file
if (!converter.Close())
throw new Exception(String.Format("Output file {0} cannot be closed. {1} " +
"(ErrorCode: 0x{2:x})", outPath, converter.ErrorMessage, converter.ErrorCode));
}
C# sample:
Java sample:
// Create the converter
converter = new Img2Pdf();
// Create encrypted output file
if (!converter.create(outPath, userPW, ownerPW, NativeLibrary.PERMISSION.ePermPrint |
NativeLibrary.PERMISSION.ePermDigitalPrint))
throw new Exception(String.format("Output file %s cannot be created. %s (ErrorCode: 0x%08x).",
outPath, converter.getErrorMessage(), converter.getErrorCode()));
// Convert pages from input image to PDF
if (!converter.createPageFromImage(inPath))
throw new Exception(String.format("Pages cannot be created from image input %s. %s " +
"(ErrorCode: 0x%08x).", inPath, converter.getErrorMessage(), converter.getErrorCode()));
// Close output file
if (!converter.close())
throw new Exception(String.format("Output file %s cannot be closed. %s (ErrorCode: 0x%08x).",
outPath, converter.getErrorMessage(), converter.getErrorCode()));
Java sample:
C sample:
pConverter = Img2PdfCreateObject();
// Create encrypted output file
if (!Img2PdfCreate(pConverter, szOutPath, szUserPW, szOwnerPW, ePermDigitalPrint | ePermPrint))
{
_tprintf(_T("Output file %s cannot be created. %s (ErrorCode: 0x%08x).\n"), szOutPath, Img2PdfGetErrorMessage(pConverter), Img2PdfGetErrorCode(pConverter));
iReturnValue = 1;
goto cleanup;
}
// Convert pages from input image to PDF
if (!Img2PdfCreatePageFromImage(pConverter, szInPath))
{
_tprintf(_T("Pages cannot be created from image input %s. %s (ErrorCode: 0x%08x).\n"), szInPath, Img2PdfGetErrorMessage(pConverter), Img2PdfGetErrorCode(pConverter));
iReturnValue = 1;
goto cleanup;
}
// Close output file
if (!Img2PdfClose(pConverter))
{
_tprintf(_T("Output file %s cannot be closed. %s (ErrorCode: 0x%08x).\n"), szOutPath, Img2PdfGetErrorMessage(pConverter), Img2PdfGetErrorCode(pConverter));
iReturnValue = 1;
goto cleanup;
}
C sample:
C# sample:
// Create the converter
using (Img2Pdf converter = new Img2Pdf())
{
// Create output file
if (!converter.Create(outPath, "", "", PDFPermission.ePermNoEncryption))
throw new Exception(String.Format("Output file {0} cannot be created. {1}" +
"(ErrorCode: 0x{2:x})", outPath, converter.ErrorMessage, converter.ErrorCode));
// Set info dictionary
converter.SetInfoEntry("Title", "Your Title");
converter.SetInfoEntry("Author", "Your Author");
converter.SetInfoEntry("Creator", "Your Creator");
converter.SetInfoEntry("Subject", "Your Subject");
converter.SetInfoEntry("Producer", "Your Producer");
// Convert pages from input image to PDF
if (!converter.CreatePageFromImage(inPath))
throw new Exception(String.Format("Pages cannot be created from image input {0}. {1}" +
"(ErrorCode: 0x{2:x})", inPath, converter.ErrorMessage, converter.ErrorCode));
// Close output file
if (!converter.Close())
throw new Exception(String.Format("Output file {0} cannot be closed. {1} " +
"(ErrorCode: 0x{2:x})", outPath, converter.ErrorMessage, converter.ErrorCode));
}
C# sample:
Java sample:
// Create the converter
converter = new Img2Pdf();
// Create output file
if (!converter.create(outPath, "", "", NativeLibrary.PERMISSION.ePermNoEncryption))
throw new Exception(String.format("Output file %s cannot be created. %s (ErrorCode: 0x%08x).",
outPath, converter.getErrorMessage(), converter.getErrorCode()));
// Set info dictionary
converter.setInfoEntry("Title", "Your Title");
converter.setInfoEntry("Author", "Your Author");
converter.setInfoEntry("Creator", "Your Creator");
converter.setInfoEntry("Subject", "Your Subject");
converter.setInfoEntry("Producer", "Your Producer");
// Convert pages from input image to PDF
if (!converter.createPageFromImage(inPath))
throw new Exception(String.format("Pages cannot be created from image input %s. %s " +
"(ErrorCode: 0x%08x).", inPath, converter.getErrorMessage(), converter.getErrorCode()));
// Close output file
if (!converter.close())
throw new Exception(String.format("Output file %s cannot be closed. %s (ErrorCode: 0x%08x).",
outPath, converter.getErrorMessage(), converter.getErrorCode()));
Java sample:
C sample:
// Create the converter
pConverter = Img2PdfCreateObject();
// Create output file
if (!Img2PdfCreate(pConverter, szOutPath, _T(""), _T(""), ePermNoEncryption))
{
_tprintf(_T("Output file %s cannot be created. %s (ErrorCode: 0x%08x).\n"), szOutPath, Img2PdfGetErrorMessage(pConverter), Img2PdfGetErrorCode(pConverter));
iReturnValue = 1;
goto cleanup;
}
// Set info dictionary
Img2PdfSetInfoEntry(pConverter, _T("Title"), _T("Your Title"));
Img2PdfSetInfoEntry(pConverter, _T("Author"), _T("Your Author"));
Img2PdfSetInfoEntry(pConverter, _T("Creator"), _T("Your Creator"));
Img2PdfSetInfoEntry(pConverter, _T("Subject"), _T("Your Subject"));
Img2PdfSetInfoEntry(pConverter, _T("Producer"), _T("Your Producer"));
// Convert pages from input image to PDF
if (!Img2PdfCreatePageFromImage(pConverter, szInPath))
{
_tprintf(_T("Pages cannot be created from image input %s. %s (ErrorCode: 0x%08x).\n"), szInPath, Img2PdfGetErrorMessage(pConverter), Img2PdfGetErrorCode(pConverter));
iReturnValue = 1;
goto cleanup;
}
// Close output file
if (!Img2PdfClose(pConverter))
{
_tprintf(_T("Output file %s cannot be closed. %s (ErrorCode: 0x%08x).\n"), szOutPath, Img2PdfGetErrorMessage(pConverter), Img2PdfGetErrorCode(pConverter));
iReturnValue = 1;
goto cleanup;
}
C sample:
C# sample:
// Create the converter
using (Img2Pdf converter = new Img2Pdf())
{
// Set linearization
converter.Linearize = true;
// Create output file
if (!converter.Create(outPath, "", "", PDFPermission.ePermNoEncryption))
throw new Exception(String.Format("Output file {0} cannot be created. {1} " +
"(ErrorCode: 0x{2:x})", outPath, converter.ErrorMessage, converter.ErrorCode));
// Convert pages from input image to PDF
if (!converter.CreatePageFromImage(inPath))
throw new Exception(String.Format("Pages cannot be created from image input {0}. {1}" +
"(ErrorCode: 0x{2:x})", inPath, converter.ErrorMessage, converter.ErrorCode));
// Close output file
if (!converter.Close())
throw new Exception(String.Format("Output file {0} cannot be closed. {1} " +
"(ErrorCode: 0x{2:x})", outPath, converter.ErrorMessage, converter.ErrorCode));
}
C# sample:
Java sample:
// Create the converter
converter = new Img2Pdf();
// Set linearization
converter.setLinearize(true);
// Create output file
if (!converter.create(outPath, "", "", NativeLibrary.PERMISSION.ePermNoEncryption))
throw new Exception(String.format("Output file %s cannot be created. %s (ErrorCode: 0x%08x).",
outPath, converter.getErrorMessage(), converter.getErrorCode()));
// Convert pages from input image to PDF
if (!converter.createPageFromImage(inPath))
throw new Exception(String.format("Pages cannot be created from image input %s. %s " +
"(ErrorCode: 0x%08x).", inPath, converter.getErrorMessage(), converter.getErrorCode()));
// Close output file
if (!converter.close())
throw new Exception(String.format("Output file %s cannot be closed. %s (ErrorCode: 0x%08x).",
outPath, converter.getErrorMessage(), converter.getErrorCode()));
Java sample:
C sample:
// Create the converter
pConverter = Img2PdfCreateObject();
// Set linearization
Img2PdfSetLinearize(pConverter, true);
// Create output file
if (!Img2PdfCreate(pConverter, szOutPath, _T(""), _T(""), ePermNoEncryption))
{
_tprintf(_T("Output file %s cannot be created. %s (ErrorCode: 0x%08x).\n"), szOutPath, Img2PdfGetErrorMessage(pConverter), Img2PdfGetErrorCode(pConverter));
iReturnValue = 1;
goto cleanup;
}
// Convert pages from input image to PDF
if (!Img2PdfCreatePageFromImage(pConverter, szInPath))
{
_tprintf(_T("Pages cannot be created from image input %s. %s (ErrorCode: 0x%08x).\n"), szInPath, Img2PdfGetErrorMessage(pConverter), Img2PdfGetErrorCode(pConverter));
iReturnValue = 1;
goto cleanup;
}
// Close output file
if (!Img2PdfClose(pConverter))
{
_tprintf(_T("Output file %s cannot be closed. %s (ErrorCode: 0x%08x).\n"), szOutPath, Img2PdfGetErrorMessage(pConverter), Img2PdfGetErrorCode(pConverter));
iReturnValue = 1;
goto cleanup;
}
C sample:
C# sample:
// Create the converter
using (Img2Pdf converter = new Img2Pdf())
{
// Set size of output page
converter.SetPageSize(width, height);
// Create output file
if (!converter.Create(outPath, "", "", PDFPermission.ePermNoEncryption))
throw new Exception(String.Format("Output file {0} cannot be created. {1} " +
"(ErrorCode: 0x{2:x})", outPath, converter.ErrorMessage, converter.ErrorCode));
// Convert pages from input image to PDF
if (!converter.CreatePageFromImage(inPath))
throw new Exception(String.Format("Pages cannot be created from image input {0}. " +
"{1} (ErrorCode: 0x{2:x})", inPath, converter.ErrorMessage, converter.ErrorCode));
// Close output file
if (!converter.Close())
throw new Exception(String.Format("Output file {0} cannot be closed. {1} " +
"(ErrorCode: 0x{2:x})", outPath, converter.ErrorMessage, converter.ErrorCode));
}
C# sample:
Java sample:
// Create the converter
converter = new Img2Pdf();
// Set size of output page
converter.setPageSize(width, height);
// Create output file
if (!converter.create(outPath, "", "", NativeLibrary.PERMISSION.ePermNoEncryption))
throw new Exception(String.format("Output file %s cannot be created. %s (ErrorCode: 0x%08x).",
outPath, converter.getErrorMessage(), converter.getErrorCode()));
// Convert pages from input image to PDF
if (!converter.createPageFromImage(inPath))
throw new Exception(String.format("Pages cannot be created from image input %s. %s " +
"(ErrorCode: 0x%08x).", inPath, converter.getErrorMessage(), converter.getErrorCode()));
// Close output file
if (!converter.close())
throw new Exception(String.format("Output file %s cannot be closed. %s (ErrorCode: 0x%08x).",
outPath, converter.getErrorMessage(), converter.getErrorCode()));
Java sample:
C sample:
// Create the converter
pConverter = Img2PdfCreateObject();
// Set page size
Img2PdfSetPageSize(pConverter, fWidth, fHeight);
// Create output file
if (!Img2PdfCreate(pConverter, szOutPath, _T(""), _T(""), ePermNoEncryption))
{
_tprintf(_T("Output file %s cannot be created. %s (ErrorCode: 0x%08x).\n"), szOutPath, Img2PdfGetErrorMessage(pConverter), Img2PdfGetErrorCode(pConverter));
iReturnValue = 1;
goto cleanup;
}
// Convert pages from input image to PDF
if (!Img2PdfCreatePageFromImage(pConverter, szInPath))
{
_tprintf(_T("Pages cannot be created from image input %s. %s (ErrorCode: 0x%08x).\n"), szInPath, Img2PdfGetErrorMessage(pConverter), Img2PdfGetErrorCode(pConverter));
iReturnValue = 1;
goto cleanup;
}
// Close output file
if (!Img2PdfClose(pConverter))
{
_tprintf(_T("Output file %s cannot be closed. %s (ErrorCode: 0x%08x).\n"), szOutPath, Img2PdfGetErrorMessage(pConverter), Img2PdfGetErrorCode(pConverter));
iReturnValue = 1;
goto cleanup;
}
C sample:
Document Assembly
C# sample:
// Create the converter
using (Img2Pdf converter = new Img2Pdf())
{
// Set page size
converter.SetPageSize(595, 842);
// Create output file
if (!converter.Create(outPath, "", "", PDFPermission.ePermNoEncryption))
throw new Exception(String.Format("Output file {0} cannot be created. {1} " +
"(ErrorCode: 0x{2:x})", outPath, converter.ErrorMessage, converter.ErrorCode));
// Loop through all input files
for (int i = 0; i < args.Length - 1; i++)
{
// Add pages from input image
if (!converter.CreatePageFromImage(inPath[i]))
throw new Exception(String.Format("Pages cannot be created from image input {0}. {1}" +
" (ErrorCode: 0x{2:x})", inPath[i], converter.ErrorMessage, converter.ErrorCode));
}
// Close output file
if (!converter.Close())
throw new Exception(String.Format("Output file {0} cannot be closed. {1} " +
"(ErrorCode: 0x{2:x})", outPath, converter.ErrorMessage, converter.ErrorCode));
}
C# sample:
Java sample:
// Create the converter
converter = new Img2Pdf();
// Set page size
converter.setPageSize(595, 842);
// Create output file
if (!converter.create(outPath, "", "", NativeLibrary.PERMISSION.ePermNoEncryption))
throw new Exception(String.format("Output file %s cannot be created. %s (ErrorCode: 0x%08x).",
outPath, converter.getErrorMessage(), converter.getErrorCode()));
// Loop through all input files
for (int i = 0; i < args.length - 1; i++)
{
// Add pages from input image
if (!converter.createPageFromImage(inPath[i]))
throw new Exception(String.format("Pages cannot be created from image input %s. %s " +
"(ErrorCode: 0x%08x).", inPath[i], converter.getErrorMessage(),
converter.getErrorCode()));
}
// Close output file
if (!converter.close())
throw new Exception(String.format("Output file %s cannot be closed. %s (ErrorCode: 0x%08x).",
outPath, converter.getErrorMessage(), converter.getErrorCode()));
Java sample:
C sample:
// Create the converter
pConverter = Img2PdfCreateObject();
// Set page size
Img2PdfSetPageSize(pConverter, 595.0, 842.0);
// Create output file
if (!Img2PdfCreate(pConverter, szOutPath, _T(""), _T(""), ePermNoEncryption))
{
_tprintf(_T("Output file %s cannot be created. %s (ErrorCode: 0x%08x).\n"), szOutPath, Img2PdfGetErrorMessage(pConverter), Img2PdfGetErrorCode(pConverter));
iReturnValue = 1;
goto cleanup;
}
// Loop through all input files
for (int i = 0; i < argc - 2; i++)
{
// Convert pages from input image to PDF
if (!Img2PdfCreatePageFromImage(pConverter, szInPath[i]))
{
_tprintf(_T("Pages cannot be created from image input %s. %s (ErrorCode: 0x%08x).\n"), szInPath[i], Img2PdfGetErrorMessage(pConverter), Img2PdfGetErrorCode(pConverter));
iReturnValue = 1;
goto cleanup;
}
}
// Close output file
if (!Img2PdfClose(pConverter))
{
_tprintf(_T("Output file %s cannot be closed. %s (ErrorCode: 0x%08x).\n"), szOutPath, Img2PdfGetErrorMessage(pConverter), Img2PdfGetErrorCode(pConverter));
iReturnValue = 1;
goto cleanup;
}
C sample:
C# sample:
// Create the converter
using (Img2Pdf converter = new Img2Pdf())
{
// Create codec for input
using (PdfCodec inCodec = new PdfCodec())
{
// Open input image
if (!inCodec.Open(inPath))
throw new Exception(String.Format("Input image {0} cannot be opened. {1} " +
"(ErrorCode: 0x{2:x})", inPath, inCodec.ErrorMessage, inCodec.ErrorCode));
// Loop over all pages of image file and create each time a new PDF
for (int iPage = 1; iPage <= inCodec.PageCount; iPage++)
{
inCodec.PageNo = iPage;
string docPath = Path.Combine(Path.GetDirectoryName(outPath),
Path.ChangeExtension(Path.GetFileNameWithoutExtension(outPath) + iPage.ToString(),
"pdf"));
// Create output file
if (!converter.Create(docPath, "", "", PDFPermission.ePermNoEncryption))
throw new Exception(String.Format("Output file {0} cannot be created. {1} " +
"(ErrorCode: 0x{2:x})", outPath, converter.ErrorMessage, converter.ErrorCode));
// Create pages from image codec
if (!converter.CreatePageFromCodec(inCodec))
throw new Exception(String.Format("Page {0} of the image could not be converted " +
"to PDF {1}. {2} (ErrorCode: 0x{3:x})", iPage, outPath, converter.ErrorMessage,
converter.ErrorCode));
}
// Close output file
if (!converter.Close())
throw new Exception(String.Format("Output file {0} cannot be closed. {1} " +
"(ErrorCode: 0x{2:x})", outPath, converter.ErrorMessage, converter.ErrorCode));
}
}
C# sample:
Java sample:
// Create the converter
converter = new Img2Pdf();
// Create codec for input
inCodec = new Codec();
// Open input image
if (!inCodec.open(inPath))
throw new Exception(String.format("Input image %s cannot be opened. %s (ErrorCode: 0x%08x).",
inPath, inCodec.getErrorMessage(), inCodec.getErrorCode()));
// Loop over all pages of image file and create each time a new PDF
for (int iPage = 1; iPage <= inCodec.getPageCount(); iPage++)
{
inCodec.setPageNo(iPage);
File file = new File(outPath);
String docPath = file.getName();
docPath = docPath.substring(0, docPath.lastIndexOf(".")) + iPage + ".pdf";
// Create output file
if (!converter.create(docPath, "", "", NativeLibrary.PERMISSION.ePermNoEncryption))
throw new Exception(String.format("Output file %s cannot be created. %s " +
"(ErrorCode: 0x%08x).", outPath, converter.getErrorMessage(),
converter.getErrorCode()));
// Create pages from image codec
if (!converter.createPageFromCodec(inCodec))
throw new Exception(String.format("Page %d of the image could not be converted to " +
"PDF %s. %s (ErrorCode: 0x%08x).", iPage, outPath, converter.getErrorMessage(),
converter.getErrorCode()));
}
// Close output file
if (!converter.close())
throw new Exception(String.format("Output file %s cannot be closed. %s (ErrorCode: 0x%08x).",
outPath, converter.getErrorMessage(), converter.getErrorCode()));
Java sample:
C sample:
// Create the converter
pConverter = Img2PdfCreateObject();
// Create codec for input
pInCodec = PdfCodecCreateObject();
// Open input image
if (!PdfCodecOpen(pInCodec, szInPath))
{
_tprintf(_T("Input image %s cannot be opened. %s (ErrorCode: 0x%08x).\n"), szInPath, PdfCodecGetErrorMessageA(pInCodec), PdfCodecGetErrorCode(pInCodec));
iReturnValue = 1;
goto cleanup;
}
// Loop over all pages of image file and create each time a new PDF
for (int iPage = 1; iPage <= PdfCodecGetPageCount(pInCodec); iPage++)
{
PdfCodecSetPageNo(pInCodec, iPage);
// Change extension
_tcscpy(szDocPath, szOutPath);
_tcstok(szDocPath, _T("."));
_stprintf(szBuffer, "%d", iPage);
_tcscat(szDocPath, szBuffer);
_tcscat(szDocPath, _T(".pdf"));
// Create output file
if (!Img2PdfCreate(pConverter, szDocPath, _T(""), _T(""), ePermNoEncryption))
{
_tprintf(_T("Output file %s cannot be created. %s (ErrorCode: 0x%08x).\n"), szOutPath, Img2PdfGetErrorMessage(pConverter), Img2PdfGetErrorCode(pConverter));
iReturnValue = 1;
goto cleanup;
}
// Create pages from image codec
if (!Img2PdfCreatePageFromCodec(pConverter, pInCodec))
{
_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));
iReturnValue = 1;
goto cleanup;
}
}
// Close output file
if (!Img2PdfClose(pConverter))
{
_tprintf(_T("Output file %s cannot be closed. %s (ErrorCode: 0x%08x).\n"), szOutPath, Img2PdfGetErrorMessage(pConverter), Img2PdfGetErrorCode(pConverter));
iReturnValue = 1;
goto cleanup;
}
C sample:
In Memory
C# sample:
// Create the converter
using (Img2Pdf converter = new Img2Pdf())
{
// Create PDF in memory
if (!converter.CreateInMemory())
throw new Exception(String.Format("Output file {0} cannot be created. {1} " +
"(ErrorCode: 0x{2:x})", outImage, converter.ErrorMessage, converter.ErrorCode));
// Create codec for input
using (PdfCodec inCodec = new PdfCodec())
{
// Open image from memory
if (!inCodec.OpenMem(inBuffer))
throw new Exception(String.Format("Codec cannot be opened. {0} (ErrorCode: 0x{1:x})",
inCodec.ErrorMessage, inCodec.ErrorCode));
// Convert all pages
for (int iPage = 1; iPage <= inCodec.PageCount; iPage++)
{
inCodec.PageNo = iPage;
// Create pages from image codec
if (!converter.CreatePageFromCodec(inCodec))
throw new Exception(String.Format("Page {0} of the image could not be converted" +
" to PDF {1}. {2} (ErrorCode: 0x{3:x}) ", iPage, outImage,
converter.ErrorMessage, converter.ErrorCode));
}
// Close output file
if (!converter.Close())
throw new Exception(String.Format("Output file {0} cannot be closed. {1} " +
"(ErrorCode: 0x{2:x})", outImage, converter.ErrorMessage, converter.ErrorCode));
}
// Get PDF in buffer
outBuffer = converter.GetPdf();
if (outBuffer == null)
throw new Exception(String.Format("Getting buffer of output PDF failed. {0} " +
"(ErrorCode: 0x{1:x})", converter.ErrorMessage, converter.ErrorCode));
// Write bytes to output file
File.WriteAllBytes(outImage, outBuffer);
}
C# sample:
Java sample:
// Create the converter
converter = new Img2Pdf();
// Create PDF in memory
if (!converter.createInMemory())
throw new Exception(String.format("Output file %s cannot be created in memory. %s" +
"(ErrorCode: 0x%08x).", outPath, converter.getErrorMessage(), converter.getErrorCode()));
// Create codec for input
inCodec = new Codec();
// Open image from memory
if (!inCodec.openMem(inBuffer))
throw new Exception(String.format("Input cannot be opened from memory. %s (ErrorCode: 0x%08x).",
inCodec.getErrorMessage(), inCodec.getErrorCode()));
// Convert all pages
for (int iPage = 1; iPage <= inCodec.getPageCount(); iPage++)
{
inCodec.setPageNo(iPage);
// Create pages from image codec
if (!converter.createPageFromCodec(inCodec))
throw new Exception(String.format("Page %d of the image could not be converted to PDF " +
"%s. %s (ErrorCode: 0x%08x).", iPage, outPath, converter.getErrorMessage(),
converter.getErrorCode()));
}
// Close output file
if (!converter.close())
throw new Exception(String.format("Output file %s cannot be closed. %s (ErrorCode: 0x%08x).",
outPath, converter.getErrorMessage(), converter.getErrorCode()));
// Get PDF in buffer
outBuffer = converter.getPdf();
if (outBuffer == null)
throw new Exception(String.format("Getting buffer of output PDF failed. %s " +
"(ErrorCode: 0x%08x).", converter.getErrorMessage(), converter.getErrorCode()));
// Write bytes to output file
Files.write(Paths.get(outPath), outBuffer, StandardOpenOption.CREATE_NEW);
Java sample:
C sample:
// Create the converter
pConverter = Img2PdfCreateObject();
// Create PDF in memory
if (!Img2PdfCreateInMemory(pConverter))
{
_tprintf(_T("Codec cannot be opened. %s (ErrorCode: 0x%08x).\n"), Img2PdfGetErrorMessage(pConverter), Img2PdfGetErrorCode(pConverter));
iReturnValue = 1;
goto cleanup;
}
// Create codec for input
pInCodec = PdfCodecCreateObject();
// Open image from memory
if (!PdfCodecOpenMem(pInCodec, pInBuffer, nLength))
{
_tprintf(_T("Codec cannot be opened. %s (ErrorCode: 0x%08x).\n"), PdfCodecGetErrorMessageA(pInCodec), PdfCodecGetErrorCode(pInCodec));
iReturnValue = 1;
goto cleanup;
}
// Convert all pages
for (int iPage = 1; iPage <= PdfCodecGetPageCount(pInCodec); iPage++)
{
PdfCodecSetPageNo(pInCodec, iPage);
// Create pages from image codec
if (!Img2PdfCreatePageFromCodec(pConverter, pInCodec))
{
_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));
}
}
// Close output file
if (!Img2PdfClose(pConverter))
{
_tprintf(_T("Output file %s cannot be closed. %s (ErrorCode: 0x%08x).\n"), szOutImage, Img2PdfGetErrorMessage(pConverter), Img2PdfGetErrorCode(pConverter));
iReturnValue = 1;
goto cleanup;
}
// Get PDF in buffer
TPDFByteArray* pOutBuffer = Img2PdfGetPdf(pConverter);
if ((pData = _tfopen(szOutImage, _T("wb"))) == NULL)
{
_tprintf(_T("Getting buffer of output PDF failed. %s (ErrorCode: 0x%08x).\n"), Img2PdfGetErrorMessage(pConverter), Img2PdfGetErrorCode(pConverter));
iReturnValue = 1;
goto cleanup;
}
// Write bytes to output file
fwrite(pOutBuffer->m_pData, pOutBuffer->m_nLength, 1, pData);
fclose(pData);
C sample:
Image to Image Assembly
C# sample:
// Create codec for output
using (PdfCodec outCodec = new PdfCodec())
{
// Create output file
if (!outCodec.Create(outImage))
throw new Exception(String.Format("Output file {0} cannot be created. {1}" +
"(ErrorCode: 0x{2:x})", outImage, outCodec.ErrorMessage, outCodec.ErrorCode));
// Create image copier
using (Img2Img copier = new Img2Img())
{
// Loop through all input files
for (int i = 0; i < args.Length - 1; i++)
{
// Create codec for input
using (PdfCodec inCodec = new PdfCodec())
{
// Open input image
if (!inCodec.Open(inImage[i]))
throw new Exception(String.Format("Input image {0} cannot be opened. {1} " +
"(ErrorCode: 0x{2:x})", inImage, inCodec.ErrorMessage, inCodec.ErrorCode));
// Convert all pages
for (int iPage = 1; iPage <= inCodec.PageCount; iPage++)
{
inCodec.PageNo = iPage;
// Copy page from input to output
if (!copier.CopyPage(inCodec, outCodec))
throw new Exception(String.Format("Input cannot be copied to output. " +
"{0} (ErrorCode: 0x{1:x}", copier.ErrorMessage, copier.ErrorCode));
}
}
}
}
}
C# sample:
Java sample:
// Create codec for output
outCodec = new Codec();
// Create output file
if (!outCodec.create(outImage))
throw new Exception(String.format("Output file %s cannot be created. %s (ErrorCode: 0x%08x).",
outImage, outCodec.getErrorMessage(), outCodec.getErrorCode()));
// Create image copier
copier = new Img2Img();
// Loop through all input files
for (int i = 0; i < args.length - 1; i++)
{
// Create codec for input
inCodec = new Codec();
// Open input image
if (!inCodec.open(inImage[i]))
throw new Exception(String.format("Input image %s cannot be opened. %s " +
"(ErrorCode: 0x%08x).", inImage, inCodec.getErrorMessage(), inCodec.getErrorCode()));
// Convert all pages
for (int iPage = 1; iPage <= inCodec.getPageCount(); iPage++)
{
inCodec.setPageNo(iPage);
// Copy page from input to output
if (!copier.copyPage(inCodec, outCodec))
throw new Exception(String.format("Input %s cannot be copied to output. %s " +
"(ErrorCode: 0x%08x).", inImage, copier.getErrorMessage(), copier.getErrorCode()));
}
}
Java sample:
C sample:
// Create codec for output
pOutCodec = PdfCodecCreateObject();
// Create output file
if (!PdfCodecCreate(pOutCodec, szOutImage))
{
_tprintf(_T("Output file %s cannot be created. %s (ErrorCode: 0x%08x).\n"), szOutImage, PdfCodecGetErrorMessageA(pOutCodec), PdfCodecGetErrorCode(pOutCodec));
iReturnValue = 1;
goto cleanup;
}
// Create image copier
pCopier = Img2ImgCreateObject();
// Loop through all input files
for (int i = 0; i < argc - 2; i++)
{
// Create codec for input
pInCodec = PdfCodecCreateObject();
// Open input image
if (!PdfCodecOpen(pInCodec, szInImage[i]))
{
_tprintf(_T("Input file %s cannot be opened. %s (ErrorCode: 0x%08x).\n"), szInImage[i], PdfCodecGetErrorMessageA(pInCodec), PdfCodecGetErrorCode(pInCodec));
iReturnValue = 1;
goto cleanup;
}
// Convert all pages
for (int iPage = 1; iPage <= PdfCodecGetPageCount(pInCodec); iPage++)
{
PdfCodecSetPageNo(pInCodec, iPage);
// Copy page from input to output
if (!Img2ImgCopyPage(pCopier, pInCodec, pOutCodec))
{
_tprintf(_T("Input cannot be copied to output. %s (ErrorCode: 0x%08x).\n"), Img2ImgGetErrorMessageA(pCopier), Img2ImgGetErrorCode(pCopier));
iReturnValue = 1;
goto cleanup;
}
}
}
C sample:
C# sample:
// Create codec for input
using (PdfCodec inCodec = new PdfCodec())
{
// Open image file
if (!inCodec.Open(inImage))
throw new Exception(String.Format("Image file {0} cannot be opened. {1} " +
"(ErrorCode: 0x{2:x})", inImage, inCodec.ErrorMessage, inCodec.ErrorCode));
// Loop over all pages of image file and create each time a new image file
for (int iPage = 1; iPage <= inCodec.PageCount; iPage++)
{
inCodec.PageNo = iPage;
string imagePath = Path.Combine(Path.GetDirectoryName(outImage),
Path.ChangeExtension(Path.GetFileNameWithoutExtension(outImage) + iPage.ToString(),
extension));
// Create image copier
using (Img2Img copier = new Img2Img())
{
// Convert present image to separate single-page image
if (!copier.ConvertFile(inImage, imagePath, iPage, iPage))
throw new Exception(String.Format("Page {0} of the image file cannot be " +
"converted. {1} (ErrorCode: 0x{2:x})", iPage, copier.ErrorMessage,
copier.ErrorCode));
}
}
}
C# sample:
Java sample:
// Create codec for input
inCodec = new Codec();
// Open image file
if (!inCodec.open(inImage))
throw new Exception(String.format("Input image %s cannot be opened. %s (ErrorCode: 0x%08x).",
inImage, inCodec.getErrorMessage(), inCodec.getErrorCode()));
// Loop over all pages of image file and create each time a new image file
for (int iPage = 1; iPage <= inCodec.getPageCount(); iPage++)
{
inCodec.setPageNo(iPage);
String imagePath = file.getName();
imagePath = imagePath.substring(0, imagePath.lastIndexOf(".")) + iPage + extension;
// Create image copier
copier = new Img2Img();
// Convert present image to separate single-page image
if (!copier.convertFile(inImage, imagePath, iPage, iPage))
throw new Exception(String.format("Page %d of the image file cannot be converted. %s " +
"(ErrorCode: 0x%08x).", iPage, copier.getErrorMessage(), copier.getErrorCode()));
}
Java sample:
C sample:
// Create codec for input
pInCodec = PdfCodecCreateObject();
// Open image file
if (!PdfCodecOpen(pInCodec, szInImage))
{
_tprintf(_T("Image file %s cannot be opened. %s (ErrorCode: 0x%08x).\n"), szInImage, PdfCodecGetErrorMessageA(pInCodec), PdfCodecGetErrorCode(pInCodec));
iReturnValue = 1;
goto cleanup;
}
// Loop over all pages of image file and create each time a new image file
for (int iPage = 1; iPage <= PdfCodecGetPageCount(pInCodec); iPage++)
{
PdfCodecSetPageNo(pInCodec, iPage);
// Change extension
_tcscpy(szImagePath, szOutImage);
_tcstok(szImagePath, _T("."));
_stprintf(szBuffer, "%d", iPage);
_tcscat(szImagePath, szBuffer);
_tcscat(szImagePath, szExt);
// Create image copier
pCopier = Img2ImgCreateObject();
// Convert present image to separate single-page image
if (!Img2ImgConvertFile(pCopier, szInImage, szImagePath, iPage, iPage))
{
_tprintf(_T("Page %d of the image file cannot be converted. %s (ErrorCode: 0x%08x).\n"), iPage, Img2ImgGetErrorMessageA(pCopier), Img2ImgGetErrorCode(pCopier));
iReturnValue = 1;
goto cleanup;
}
}
C sample:
Image to Image Conversion
C# sample:
// Create codec for input
using (PdfCodec inCodec = new PdfCodec())
{
// Open input image
if (!inCodec.Open(inImage))
throw new Exception(String.Format("Input file {0} cannot be opened. {1} " +
"(ErrorCode: 0x{2:x})", inImage, inCodec.ErrorMessage, inCodec.ErrorCode));
// Create codec for output
using (PdfCodec outCodec = new PdfCodec())
{
// Create output file
if (!outCodec.Create(outImage))
throw new Exception(String.Format("Output file {0} cannot be created. " +
"{1} (ErrorCode: 0x{2:x})", outImage, outCodec.ErrorMessage, outCodec.ErrorCode));
// Create image copier
using (Img2Img copier = new Img2Img())
{
// Set continuous compression
copier.ContinuousCompression = compression;
// Set quality
copier.ImageQuality = quality;
// Loop through all pages of input
for (int iPage = 1; iPage <= inCodec.PageCount; iPage++)
{
inCodec.PageNo = iPage;
// Copy all pages from input to output
if (!copier.CopyPage(inCodec, outCodec))
throw new Exception(String.Format("Input {0} cannot be copied to output. {1}" +
" (ErrorCode: 0x{2:x})", inImage, copier.ErrorMessage, copier.ErrorCode));
}
}
}
}
C# sample:
Java sample:
// Create codec for input
inCodec = new Codec();
// Open input image
if (!inCodec.open(inImage))
throw new Exception(String.format("Input file %s cannot be opened. %s (ErrorCode: 0x%08x).",
inImage, inCodec.getErrorMessage(), inCodec.getErrorCode()));
// Create codec for output
outCodec = new Codec();
// Create output file
if (!outCodec.create(outImage))
throw new Exception(String.format("Output file %s cannot be created. %s (ErrorCode: 0x%08x).",
outImage, outCodec.getErrorMessage(), outCodec.getErrorCode()));
// Create image copier
copier = new Img2Img();
// Set continuous compression
copier.setContinuousCompression(compression);
// Set quality
copier.setImageQuality(quality);
// Loop through all pages of input
for (int iPage = 1; iPage <= inCodec.getPageCount(); iPage++)
{
inCodec.setPageNo(iPage);
// Copy all pages from input to output
if (!copier.copyPage(inCodec, outCodec))
throw new Exception(String.format("Input %s cannot be copied to output. %s " +
"(ErrorCode: 0x%08x).", inImage, copier.getErrorMessage(), copier.getErrorCode()));
}
Java sample:
C sample:
// Create codec for input
pInCodec = PdfCodecCreateObject();
// Open input image
if (!PdfCodecOpen(pInCodec, szInImage))
{
_tprintf(_T("Input file %s cannot be opened. %s (ErrorCode: 0x%08x).\n"), szInImage, PdfCodecGetErrorMessageA(pInCodec), PdfCodecGetErrorCode(pInCodec));
iReturnValue = 1;
goto cleanup;
}
// Create codec for output
pOutCodec = PdfCodecCreateObject();
// Create output file
if (!PdfCodecCreate(pOutCodec, szOutImage))
{
_tprintf(_T("Output file %s cannot be created. %s (ErrorCode: 0x%08x).\n"), szOutImage, PdfCodecGetErrorMessageA(pOutCodec), PdfCodecGetErrorCode(pOutCodec));
iReturnValue = 1;
goto cleanup;
}
// Create image copier
pCopier = Img2ImgCreateObject();
// Set continuous compression
Img2ImgSetContinuousCompression(pCopier, eCompression);
// Set quality
Img2ImgSetImageQuality(pCopier, iQuality);
// Loop through all pages of input
for (int iPage = 1; iPage <= PdfCodecGetPageCount(pInCodec); iPage++)
{
PdfCodecSetPageNo(pInCodec, iPage);
// Copy all pages from input to output
if (!Img2ImgCopyPage(pCopier, pInCodec, pOutCodec))
{
_tprintf(_T("Input file %s cannot be copied to output. %s (ErrorCode: 0x%08x).\n"), szInImage, Img2ImgGetErrorMessageA(pCopier), Img2ImgGetErrorCode(pCopier));
iReturnValue = 1;
goto cleanup;
}
}
C sample:
C# sample:
// Create codec for input
using (PdfCodec inCodec = new PdfCodec())
{
// Open input image
if (!inCodec.Open(inImage))
throw new Exception(String.Format("Input file {0} cannot be opened. {1} " +
"(ErrorCode: 0x{2:x})", inImage, inCodec.ErrorMessage, inCodec.ErrorCode));
// Create codec for output
using (PdfCodec outCodec = new PdfCodec())
{
// Create output file
if (!outCodec.Create(outImage))
throw new Exception(String.Format("Output file {0} cannot be created. " +
"{1} (ErrorCode: 0x{2:x})", outImage, outCodec.ErrorMessage, outCodec.ErrorCode));
// Create image copier
using (Img2Img copier = new Img2Img())
{
// Set width and resolution
copier.Width = width;
copier.DPI = resolution;
// Set resampling
copier.AllowResampling = true;
// Loop through all pages of input
for (int iPage = 1; iPage <= inCodec.PageCount; iPage++)
{
inCodec.PageNo = iPage;
// Copy all pages from input to output
if (!copier.CopyPage(inCodec, outCodec))
throw new Exception(String.Format("Input {0} cannot be copied to output. {1}" +
" (ErrorCode: 0x{2:x})", inImage, copier.ErrorMessage, copier.ErrorCode));
}
}
}
}
C# sample:
Java sample:
// Create codec for input
inCodec = new Codec();
// Open input image
if (!inCodec.open(inImage))
throw new Exception(String.format("Input file %s cannot be opened. %s (ErrorCode: 0x%08x).",
inImage, inCodec.getErrorMessage(), inCodec.getErrorCode()));
// Create codec for output
outCodec = new Codec();
// Create output file
if (!outCodec.create(outImage))
throw new Exception(String.format("Output file %s cannot be created. %s (ErrorCode: 0x%08x).",
outImage, outCodec.getErrorMessage(), outCodec.getErrorCode()));
// Create image copier
copier = new Img2Img();
// Set width and resolution
copier.setWidth(width);
copier.setDPI(resolution);
// Set resampling
copier.setAllowResampling(true);
// Loop through all pages of input
for (int iPage = 1; iPage <= inCodec.getPageCount(); iPage++)
{
inCodec.setPageNo(iPage);
// Copy all pages from input to output
if (!copier.copyPage(inCodec, outCodec))
throw new Exception(String.format("Input %s cannot be copied to output. %s " +
"(ErrorCode: 0x%08x).", inImage, copier.getErrorMessage(), copier.getErrorCode()));
}
Java sample:
C sample:
// Create codec for input
pInCodec = PdfCodecCreateObject();
// Open input image
if (!PdfCodecOpen(pInCodec, szInImage))
{
_tprintf(_T("Input file %s cannot be opened. %s (ErrorCode: 0x%08x).\n"), szInImage, PdfCodecGetErrorMessageA(pInCodec), PdfCodecGetErrorCode(pInCodec));
iReturnValue = 1;
goto cleanup;
}
// Create codec for output
pOutCodec = PdfCodecCreateObject();
// Create output file
if (!PdfCodecCreate(pOutCodec, szOutImage))
{
_tprintf(_T("Output file %s cannot be created. %s (ErrorCode: 0x%08x).\n"), szOutImage, PdfCodecGetErrorMessageA(pOutCodec), PdfCodecGetErrorCode(pOutCodec));
iReturnValue = 1;
goto cleanup;
}
// Create image copier
pCopier = Img2ImgCreateObject();
// Set width and resolution
Img2ImgSetWidth(pCopier, iWidth);
Img2ImgSetDPI(pCopier, fResolution);
// Set resampling
Img2ImgGetAllowResampling(pCopier);
// Loop through all pages of input
for (int iPage = 1; iPage <= PdfCodecGetPageCount(pInCodec); iPage++)
{
PdfCodecSetPageNo(pInCodec, iPage);
// Copy all pages from input to output
if (!Img2ImgCopyPage(pCopier, pInCodec, pOutCodec))
{
_tprintf(_T("Input file %s cannot be copied to output. %s (ErrorCode: 0x%08x).\n"), szInImage, Img2ImgGetErrorMessageA(pCopier), Img2ImgGetErrorCode(pCopier));
iReturnValue = 1;
goto cleanup;
}
}
C sample: