Aperçu d'exemples

Conversion | Document Assembly | In Memory | Image to Image Assembly | Image to Image Conversion

Conversion

Convert Image to PDF and embed metadata

Convert a JPEG image to a PDF document. Set the XMP metadata of the PDF document based on a conforming XMP file, which contains information such as author, title and creator.

l'exemple C# :
// 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));
}
l'exemple Java :
// 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()));
l'exemple C :
// 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;
}

Convert Image to PDF and set compression

Convert an image to PDF. Set the compression type of color and grayscale images and optionally set the quality for lossy compression.

l'exemple C# :
// 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));
}
l'exemple Java :
// 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()));
l'exemple C :
// 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;
}

Convert Image to PDF/A

Convert an image to a PDF/A-1a document. Optionally set a different compliance level.

l'exemple C# :
// 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));
}
l'exemple Java :
// 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()));
l'exemple C :
// 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;
}

Convert Image to encrypted PDF

Convert an image to PDF. Encrypt the PDF in order to protect it against unauthorized access. The user password grants the right to open the document and to print it. The owner password grants unrestricted access.

l'exemple C# :
// 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));
}
l'exemple Java :
// 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()));
l'exemple C :
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;
}

Convert Image to PDF and set InfoDictionary

Convert an image to a PDF and set the info dictionary elements, e.g. title, author, creator and producer.

l'exemple C# :
// 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));
}
l'exemple Java :
// 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()));
l'exemple C :
// 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;
}

Convert Image to linearized PDF

Convert an image to a linearized PDF document, also known as optimized for fast web-viewing. Linearization only works with multipage documents.

l'exemple C# :
// 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));
}
l'exemple Java :
// 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()));
l'exemple C :
// 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;
}

Convert Image to PDF with a specific page size

Convert an image to PDF with pre-defined page dimensions.

l'exemple C# :
// 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));
}
l'exemple Java :
// 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()));
l'exemple C :
// 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;
}

Document Assembly

Merge multiple images to one PDF

Merge several images to a single PDF document.

l'exemple C# :
// 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));
}
l'exemple Java :
// 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()));
l'exemple C :
// 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;
}

Split multipage TIFF to single-page PDF

Split a multiple page TIFF image to single page PDF documents.

l'exemple C# :
// 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));
    }
}
l'exemple Java :
// 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()));
l'exemple C :
// 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;
}

In Memory

Create PDF from Image in memory

Read an image from a byte stream and convert it to a PDF byte stream. For demonstration purpose, the image byte stream is created from an image file and the PDF byte stream is written back to a PDF file.

l'exemple C# :
// 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);
}
l'exemple Java :
// 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);
l'exemple C :
// 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);

Image to Image Assembly

Merge multipage Images to TIFF

Merge images such as JPEG, TIFF, PNG, BMP to form a single multipage TIFF.

l'exemple C# :
// 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));
                }
            }
        }
    }
}
l'exemple Java :
// 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()));
    }
}
l'exemple C :
// 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;
        }
    }
}

Split multipage TIFF to single-page Images

Split a multiple page TIFF to single page images. Supported image formats amongst others are JPEG, TIFF, PNG and BMP.

l'exemple C# :
// 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));
        }
    }
}
l'exemple Java :
// 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()));
}
l'exemple C :
// 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;
    }
}

Image to Image Conversion

Convert Image to Image and set compression and quality

Convert an image to an image of another format. Set the compression type of color and grayscale images. In case of lossy compression, optionally set the quality.

l'exemple C# :
// 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));
            }
        }
    }
}
l'exemple Java :
// 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()));
}
l'exemple C :
// 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;
    }
}

Convert Image to Image with specific dimensions

Convert an image to an image of another format. Set specific width and resolution of the output image. The height is calculated respecting image proportions.

l'exemple C# :
// 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));
            }
        }
    }
}
l'exemple Java :
// 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()));
}
l'exemple C :
// 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;
    }
}