Beispiele-Übersicht

Konversion | Dokumentenzusammenstellung | In Memory | Zusammenstellung von Bild zu Bild | Konvertierung von Bild zu Bild

Konversion

Bild nach PDF konvertieren und Metadaten einbetten

Konvertiere ein JPEG Bild in ein PDF Dokument. Setze die XMP Metadaten des PDF Dokumentes basierend auf einer konformen XMP Datei, welche Informationen bezüglich Verfasser, Titel und Ersteller enthalten kann.

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

Bild in PDF konvertieren und Komprimierung einstellen

Konvertiere ein Bild in ein PDF. Stelle die Komprimierungsart von Farb- und Graustufenbildern - und optional die Qualität für die verlustbehaftete Komprimierung - ein.

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

Bild nach PDF/A konvertieren

Konvertiere ein Bild in ein PDF/A-1a. Optional kann eine andere Konformitätsstufe eingestellt werden.

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

Bild in verschlüsseltes PDF konvertieren

Konvertiere ein Bild in ein PDF. Verschlüssle das PDF, um es vor unbefugtem Zugriff zu schützen. Das Benutzerpasswort gewährt das Recht, das Dokument zu öffnen und auszudrucken. Das Eigentümerpasswort gewährt uneingeschränkten Zugriff.

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

Bild in PDF konvertieren und InfoDictionary einstellen

Konvertiere ein Bild in ein PDF und definiere die Elemente des Info-Dictionary, z.B. Titel, Autor, Ersteller und Produzent.

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

Bild in linearisiertes PDF konvertieren

Konvertiere ein Bild in ein linearisiertes PDF Dokument, welches auch als Optimierung für das schnelle Web-Viewing bekannt ist. Die Linearisierung funktioniert nur bei mehrseitigen Dokumenten.

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

Konvertiere Bildern in PDF mit einer bestimmten Seitengrösse

Konvertiere ein Bild in ein PDF Dokument mit vordefinierten Seitenmassen.

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

Dokumentenzusammenstellung

Mehrere Bilder zu einem PDF zusammenfügen

Führe mehrerer Bilder zu einem einzigen PDF Dokument zusammen.

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

Mehrseitiges TIFF in einseitige PDFs aufteilen

Teilen Sie ein mehrseitiges TIFF-Bild in einseitige PDF Dokumente auf.

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

PDF aus einem Bild im Speicher erstellen

Lese ein Bild aus einem Byte-Stream und konvertiere es in einen PDF-Byte-Stream. Zu Demonstrationszwecken wird der Image-Byte-Stream aus einer Bilddatei erzeugt und der PDF-Byte-Stream in eine PDF Datei zurückgeschrieben.

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

Zusammenstellung von Bild zu Bild

Zusammenfügen von mehrseitigen Bildern zu TIFF

Verschmelzen Sie Bilder wie JPEG, TIFF, PNG, BMP zu einem einzigen mehrseitigen TIFF.

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

Mehrseitiges TIFF in Einzelseiten-Bilder aufteilen

Teile ein mehrseitiges TIFF in Einzelseitenbilder auf. Unterstützte Bildformate sind unter anderem JPEG, TIFF, PNG und BMP.

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

Konvertierung von Bild zu Bild

Konvertiere Bilder in Bilder und definiere die Kompression und Qualität

Konvertiere ein Bild in ein Bild eines anderen Formats. Stelle dabei die Komprimierungsart von Farb- und Graustufenbildern ein. Im Falle einer verlustbehafteten Komprimierung kann optional die Qualität eingestellt werden.

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

Konvertiere Bilder in Bilder mit bestimmten Abmessungen

Konvertiere ein Bild in ein Bild eines anderen Formats. Lege dabei die spezifische Breite und Auflösung des Ausgabebildes fest. Die Höhe wird unter Berücksichtigung der Bildproportionen berechnet.

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