Beispiele-Übersicht

Optimierung | Entfernung | Funktionen und Konfiguration | In Memory

Optimierung

Optimiere ein PDF Dokument für die Archivierung

Verwende das Archivierungs-Profil um die Dateigrösse zu reduzieren ohne Informationsverlust - einer typischen Vorgabe für die Archivierung. Entferne redundante Informationen, führe eingebettete Schriften zusammen und reduziere sie auf die verwendeten Glyphen. Optimiere Ressourcen und komprimiere Bilder typenabhängig.

C# Beispiel:
// Create the optimizer
using (Optimizer optimizer = new Optimizer())
{
    // Choose the optimization profile for archiving
    optimizer.Profile = PDFOptimizationProfile.eOptimizationProfileArchive;

    // Open input file
    if (!optimizer.Open(inputPath, ""))
        throw new Exception(String.Format("Input file {0} cannot be opened. " +
            "{1} (ErrorCode: 0x{2:x}).", inputPath, optimizer.ErrorMessage, optimizer.ErrorCode));

    // Save output file
    if (!optimizer.SaveAs(outputPath, "", "", PDFPermission.ePermNoEncryption))
        throw new Exception(String.Format("Output file {0} cannot be created. " +
            "{1} (ErrorCode: 0x{2:x}).", outputPath, optimizer.ErrorMessage, optimizer.ErrorCode));

    // Close input file
    if (!optimizer.Close())
        throw new Exception(String.Format("Input file {0} cannot be closed. " +
            "{1} (ErrorCode: 0x{2:x}).", inputPath, optimizer.ErrorMessage, optimizer.ErrorCode));
}
Java Beispiel:
// Create the optimizer
optimizer = new PdfOptimize();

// Choose the optimization profile for archiving
optimizer.setProfile(PdfOptimize.OPTIMIZATIONPROFILE.eOptimizationProfileArchive);

// Open input file
if (!optimizer.open(inputPath, "")) 
    throw new IOException(String.format("Input file %s cannot be opened. %s (ErrorCode: 0x%08x).",
        inputPath, optimizer.getErrorMessage(), optimizer.getErrorCode()));

// Save output file
if (!optimizer.saveAs(outputPath, "", "", NativeLibrary.PERMISSION.ePermNoEncryption)) 
    throw new IOException(String.format("Output file %s cannot be created. %s (ErrorCode: 0x%08x).",
        outputPath, optimizer.getErrorMessage(), optimizer.getErrorCode()));

// Close input file
if (!optimizer.close())
    throw new IOException(String.format("Input file %s cannot be closed. %s (ErrorCode: 0x%08x).",
        inputPath, optimizer.getErrorMessage(), optimizer.getErrorCode()));
C Beispiel:
// Create the optimizer
pOptimizer = PdfOptimizeCreateObject();

// Choose the optimization profile for archiving
PdfOptimizeSetProfile(pOptimizer, eOptimizationProfileArchive);

// Open input file
if (!PdfOptimizeOpen(pOptimizer, szInputPath, _T("")))
{
    _tprintf(_T("Input file %s cannot be opened. %s (ErrorCode: 0x%08x).\n"), szInputPath,
        PdfOptimizeGetErrorMessage(pOptimizer), PdfOptimizeGetErrorCode(pOptimizer));
    iReturnValue = 1;
    goto cleanup;
}

// Save output file
if (!PdfOptimizeSaveAs(pOptimizer, szOutputPath, _T(""), _T(""), ePermNoEncryption))
{
    _tprintf(_T("Output file %s cannot be created. %s (ErrorCode: 0x%08x).\n"), szOutputPath,
        PdfOptimizeGetErrorMessage(pOptimizer), PdfOptimizeGetErrorCode(pOptimizer));
    iReturnValue = 1;
    goto cleanup;
}

// Close input amd output files
if (!PdfOptimizeClose(pOptimizer))
{
    _tprintf(_T("Input file %s cannot be closed. %s (ErrorCode: 0x%08x).\n"), szInputPath,
        PdfOptimizeGetErrorMessage(pOptimizer), PdfOptimizeGetErrorCode(pOptimizer));
    iReturnValue = 1;
    goto cleanup;
}

PDF Dokument mit Mixed Raster Content (MRC) optimieren

Reduziere die Dateigrösse von Dokumenten mit grossen Bildern, z.B. gescannten Seiten, unter Beibehaltung der Lesbarkeit von Text. Dies wird durch die Trennung der Bilder in einen Vordergrund, einen Hintergrund und eine Maskenebene erreicht. Die Vordergrund- und Hintergrundebenen werden stark heruntergerechnet und komprimiert. Die Textinformationen werden in der Maske mit einem verlustfreien Kompressionstyp gespeichert. Darüber hinaus werden redundante Objekte entfernt, Ressourcen optimiert und eingebettete Schriften zusammengeführt.

C# Beispiel:
// Create the optimizer
using (Optimizer optimizer = new Optimizer())
{
    // Choose the optimization profile for MRC
    optimizer.Profile = PDFOptimizationProfile.eOptimizationProfileMRC;

    // Set MRC foreground and background layer resolution
    optimizer.MrcLayerResolutionDPI = resolution;

    // Open input file
    if (!optimizer.Open(inputPath, ""))
        throw new Exception(String.Format("Input file {0} cannot be opened. " + 
            "{1} (ErrorCode: 0x{2:x}).", inputPath, optimizer.ErrorMessage, optimizer.ErrorCode));

    // Save output file
    if (!optimizer.SaveAs(outputPath, "", "", PDFPermission.ePermNoEncryption))
        throw new Exception(String.Format("Output file {0} cannot be created. " + 
            "{1} (ErrorCode: 0x{2:x}).", outputPath, optimizer.ErrorMessage, optimizer.ErrorCode));

    // Close input file
    if (!optimizer.Close())
        throw new Exception(String.Format("Input file {0} cannot be closed. " + 
            "{1} (ErrorCode: 0x{2:x}).", inputPath, optimizer.ErrorMessage, optimizer.ErrorCode));
}
Java Beispiel:
// Create the optimizer
optimizer = new PdfOptimize();

// Choose the optimization profile for MRC
optimizer.setProfile(PdfOptimize.OPTIMIZATIONPROFILE.eOptimizationProfileMRC);

// Set MRC foreground and background layer resolution
optimizer.setMrcLayerResolutionDPI(resolution);

// Open input file
if (!optimizer.open(inputPath, ""))
    throw new IOException(String.format("Input file %s cannot be opened. %s (ErrorCode: 0x%08x).",
        inputPath, optimizer.getErrorMessage(), optimizer.getErrorCode()));

// Save output file 
if (!optimizer.saveAs(outputPath, "", "", NativeLibrary.PERMISSION.ePermNoEncryption))
    throw new IOException(String.format("Output file %s cannot be created. %s (ErrorCode: 0x%08x).",
        outputPath, optimizer.getErrorMessage(), optimizer.getErrorCode()));

// Close input file
if (!optimizer.close())
    throw new IOException(String.format("Input file %s cannot be closed. %s (ErrorCode: 0x%08x).",
        inputPath, optimizer.getErrorMessage(), optimizer.getErrorCode()));
C Beispiel:
// Create the optimizer
pOptimizer = PdfOptimizeCreateObject();

// Choose the optimization profile for MRC
PdfOptimizeSetProfile(pOptimizer, eOptimizationProfileMRC);

// Set MRC foreground and background layer resolution
PdfOptimizeSetMrcLayerResolutionDPI(pOptimizer, fResolution);

// Open input file
if (!PdfOptimizeOpen(pOptimizer, szInputPath, _T("")))
{
    _tprintf(_T("Input file %s cannot be opened. %s (ErrorCode: 0x%08x).\n"), szInputPath,
        PdfOptimizeGetErrorMessage(pOptimizer), PdfOptimizeGetErrorCode(pOptimizer));
    iReturnValue = 1;
    goto cleanup;
}

// Save output file
if (!PdfOptimizeSaveAs(pOptimizer, szOutputPath, _T(""), _T(""), ePermNoEncryption))
{
    _tprintf(_T("Output file %s cannot be created. %s (ErrorCode: 0x%08x).\n"), szOutputPath,
        PdfOptimizeGetErrorMessage(pOptimizer), PdfOptimizeGetErrorCode(pOptimizer));
    iReturnValue = 1;
    goto cleanup;
}

// Close input file
if (!PdfOptimizeClose(pOptimizer))
{
    _tprintf(_T("Input file %s cannot be closed. %s (ErrorCode: 0x%08x).\n"), szInputPath,
        PdfOptimizeGetErrorMessage(pOptimizer), PdfOptimizeGetErrorCode(pOptimizer));
    iReturnValue = 1;
    goto cleanup;
}

Zusammenführen und subsetten von Schriften in PDF Dokument

Füge mehrere eingebettete Schriftprogramme zusammen und entferne alle nicht verwendeten Glyphen. Zusätzlich werden Typ-1-Fontprogramme in CFF (Compact Font Format) umgewandelt.

C# Beispiel:
// Create the optimizer
using (Optimizer optimizer = new Optimizer())
{
    // Choose subset and merge embedded fonts
    optimizer.SubsetFonts = true;
    optimizer.MergeEmbeddedFonts = true;

    // Convert Type1 font programs to CFF (compact font format)
    optimizer.ConvertToCFF = true;

    // Open input file
    if (!optimizer.Open(inputPath, ""))
        throw new Exception(String.Format("Input file {0} cannot be opened. " + 
            "{1} (ErrorCode: 0x{2:x}).", inputPath, optimizer.ErrorMessage, optimizer.ErrorCode));

    // Save output file
    if (!optimizer.SaveAs(outputPath, "", "", PDFPermission.ePermNoEncryption))
        throw new Exception(String.Format("Output file {0} cannot be created. " + 
            "{1} (ErrorCode: 0x{2:x}).", outputPath, optimizer.ErrorMessage, optimizer.ErrorCode));

    // Close input file
    if (!optimizer.Close())
        throw new Exception(String.Format("Input file {0} cannot be closed. " + 
            "{1} (ErrorCode: 0x{2:x}).", inputPath, optimizer.ErrorMessage, optimizer.ErrorCode));
}
Java Beispiel:
// Create the optimizer
optimizer = new PdfOptimize();

// Choose subset and merge embedded fonts
optimizer.setSubsetFonts(true);
optimizer.setMergeEmbeddedFonts(true);

// Convert Type1 font programs to CFF (compact font format)
optimizer.setConvertToCFF(true);

// Open input file
if (!optimizer.open(inputPath, ""))
    throw new IOException(String.format("Input file %s cannot be opened. %s (ErrorCode: 0x%08x).",
        inputPath, optimizer.getErrorMessage(), optimizer.getErrorCode()));

// Save output file 
if (!optimizer.saveAs(outputPath, "", "", NativeLibrary.PERMISSION.ePermNoEncryption))
    throw new IOException(String.format("Output file %s cannot be created. %s (ErrorCode: 0x%08x).",
        outputPath, optimizer.getErrorMessage(), optimizer.getErrorCode()));

// Close input file
if (!optimizer.close())
    throw new IOException(String.format("Input file %s cannot be closed. %s (ErrorCode: 0x%08x).",
        inputPath, optimizer.getErrorMessage(), optimizer.getErrorCode()));
C Beispiel:
// Create the optimizer
pOptimizer = PdfOptimizeCreateObject();

// Choose subset and merge embedded fonts
PdfOptimizeSetSubsetFonts(pOptimizer, 1);
PdfOptimizeSetMergeEmbeddedFonts(pOptimizer, 1);

// Convert Type1 font programs to CFF (compact font format)
PdfOptimizeSetConvertToCFF(pOptimizer, 1);

// Open input file
if (!PdfOptimizeOpen(pOptimizer, szInputPath, _T("")))
{
    _tprintf(_T("Input file %s cannot be opened. %s (ErrorCode: 0x%08x).\n"), szInputPath,
        PdfOptimizeGetErrorMessage(pOptimizer), PdfOptimizeGetErrorCode(pOptimizer));
    iReturnValue = 1;
    goto cleanup;
}

// Save output file
if (!PdfOptimizeSaveAs(pOptimizer, szOutputPath, _T(""), _T(""), ePermNoEncryption))
{
    _tprintf(_T("Output file %s cannot be created. %s (ErrorCode: 0x%08x).\n"), szOutputPath,
        PdfOptimizeGetErrorMessage(pOptimizer), PdfOptimizeGetErrorCode(pOptimizer));
    iReturnValue = 1;
    goto cleanup;
}

// Close input file
if (!PdfOptimizeClose(pOptimizer))
{
    _tprintf(_T("Input file %s cannot be closed. %s (ErrorCode: 0x%08x).\n"), szInputPath,
        PdfOptimizeGetErrorMessage(pOptimizer), PdfOptimizeGetErrorCode(pOptimizer));
    iReturnValue = 1;
    goto cleanup;
}

Optimieren von Bildern in PDF Dokument

Reduziere die Grösse einer PDF Datei, indem Sie eingebettete Bilder herunterrechnen und neu komprimieren. Lege eine Zielauflösung fest und definiere einen Satz von Kompressionstypen, aus denen der Optimierer intelligent auswählen kann. Stelle optional die Kompressionsqualität für verlustbehaftete Kompressionstypen ein.

C# Beispiel:
// Create the optimizer
using (Optimizer optimizer = new Optimizer())
{
    // Set candidate compression types
    optimizer.BitonalCompressions = PDFComprAttempt.eComprAttemptGroup4 | 
        PDFComprAttempt.eComprAttemptJBIG2 | PDFComprAttempt.eComprAttemptSource;
    optimizer.ContinuousCompressions = PDFComprAttempt.eComprAttemptJPEG | 
        PDFComprAttempt.eComprAttemptJPEG2000 | PDFComprAttempt.eComprAttemptSource;
    optimizer.IndexedCompressions = PDFComprAttempt.eComprAttemptFlate | 
        PDFComprAttempt.eComprAttemptLZW | PDFComprAttempt.eComprAttemptSource;

    // Set target resolution for down-sampling
    optimizer.ResolutionDPI = resolution;

    // Down-sample images if their resolution is greater than 130% of the target resolution
    optimizer.ThresholdDPI = (float)1.3 * optimizer.ResolutionDPI;

    // Apply a higher resolution to bi-tonal images
    optimizer.BitonalResolutionDPI = (float)1.2 * resolution;
    optimizer.BitonalThresholdDPI = (float)1.3 * optimizer.BitonalResolutionDPI;

    // Set image quality (for lossy compression types)
    optimizer.ImageQuality = quality;

    // Clip invisible parts of images
    optimizer.ClipImages = true;

    // Convert images' color spaces to the least complex possible
    optimizer.ReduceColorComplexity = true;

    // Open input file
    if (!optimizer.Open(inputPath, ""))
        throw new Exception(String.Format("Input file {0} cannot be opened. " + 
            "{1} (ErrorCode: 0x{2:x}).", inputPath, optimizer.ErrorMessage, optimizer.ErrorCode));

    // Save output file
    if (!optimizer.SaveAs(outputPath, "", "", PDFPermission.ePermNoEncryption))
        throw new Exception(String.Format("Output file {0} cannot be created. " + 
            "{1} (ErrorCode: 0x{2:x}).", outputPath, optimizer.ErrorMessage, optimizer.ErrorCode));

    // Close input file
    if (!optimizer.Close())
        throw new Exception(String.Format("Input file {0} cannot be closed. " + 
            "{1} (ErrorCode: 0x{2:x}).", inputPath, optimizer.ErrorMessage, optimizer.ErrorCode));
}
Java Beispiel:
// Create the optimizer
optimizer = new PdfOptimize();

// Set candidate compression types
optimizer.setBitonalCompressions(NativeLibrary.COMPRESSIONATTEMPT.eComprAttemptGroup4 | 
    NativeLibrary.COMPRESSIONATTEMPT.eComprAttemptJBIG2 | 
    NativeLibrary.COMPRESSIONATTEMPT.eComprAttemptSource);
optimizer.setContinuousCompressions(NativeLibrary.COMPRESSIONATTEMPT.eComprAttemptJPEG | 
    NativeLibrary.COMPRESSIONATTEMPT.eComprAttemptJPEG2000 | 
    NativeLibrary.COMPRESSIONATTEMPT.eComprAttemptSource);
optimizer.setIndexedCompressions(NativeLibrary.COMPRESSIONATTEMPT.eComprAttemptFlate | 
    NativeLibrary.COMPRESSIONATTEMPT.eComprAttemptLZW | 
    NativeLibrary.COMPRESSIONATTEMPT.eComprAttemptSource);

// Set target resolution for down-sampling
optimizer.setResolutionDPI(resolution);

// Down-sample images if their resolution is greater than 130% of the target resolution 
optimizer.setThresholdDPI((float)1.3 * resolution);

// Apply a higher resolution to bitonal images
optimizer.setBitonalResolutionDPI((float)1.2 * resolution);
optimizer.setBitonalThresholdDPI((float)1.3 * optimizer.getBitonalResolutionDPI());

// Set image quality (for lossy compression type)
optimizer.setImageQuality(quality);

// Clip invisible parts of images
optimizer.setClipImages(true);

// Convert images' color spaces to the least complex possible
optimizer.setReduceColorComplexity(true);

// Open input file
if (!optimizer.open(inputPath, ""))
    throw new IOException(String.format("Input file %s cannot be opened. %s (ErrorCode: 0x%08x).",
        inputPath, optimizer.getErrorMessage(), optimizer.getErrorCode()));

// Save output file 
if (!optimizer.saveAs(outputPath, "", "", NativeLibrary.PERMISSION.ePermNoEncryption))
    throw new IOException(String.format("Output file %s cannot be created. %s (ErrorCode: 0x%08x).",
        outputPath, optimizer.getErrorMessage(), optimizer.getErrorCode()));

// Close input file
if (!optimizer.close())
    throw new IOException(String.format("Input file %s cannot be closed. %s (ErrorCode: 0x%08x).",
        inputPath, optimizer.getErrorMessage(), optimizer.getErrorCode()));
C Beispiel:
// Create the optimizer
pOptimizer = PdfOptimizeCreateObject();

// Set candidate compression type
PdfOptimizeSetBitonalCompressions(pOptimizer, eComprAttemptGroup4 | eComprAttemptJBIG2 | 
    eComprAttemptSource);
PdfOptimizeSetContinuousCompressions(pOptimizer, eComprAttemptJPEG | eComprAttemptJPEG2000 | 
    eComprAttemptSource);
PdfOptimizeSetIndexedCompressions(pOptimizer, eComprAttemptFlate | eComprAttemptLZW | 
    eComprAttemptSource);

// Set target resolution for down-sampling
PdfOptimizeSetResolutionDPI(pOptimizer, fResolution);

// Down-sample images if their resolution exceeds 130% of the target resolution
PdfOptimizeSetThresholdDPI(pOptimizer, 1.3f * PdfOptimizeGetResolutionDPI(pOptimizer));

// Apply a 20% higher resolution to bi-tonal images
PdfOptimizeSetBitonalResolutionDPI(pOptimizer, 1.2f * fResolution);
PdfOptimizeSetBitonalThresholdDPI(pOptimizer, 
    1.3f * PdfOptimizeGetBitonalResolutionDPI(pOptimizer));

// Set image quality (for lossy compression types)
PdfOptimizeSetImageQuality(pOptimizer, iQuality);

// Clip invisible parts of images
PdfOptimizeSetClipImages(pOptimizer, 1);

// Convert images' color spaces to the least complex possible
PdfOptimizeSetReduceColorComplexity(pOptimizer, 1);

// Open input file
if (!PdfOptimizeOpen(pOptimizer, szInputPath, _T("")))
{
    _tprintf(_T("Input file %s cannot be opened. %s (ErrorCode: 0x%08x).\n"), szInputPath,
        PdfOptimizeGetErrorMessage(pOptimizer), PdfOptimizeGetErrorCode(pOptimizer));
    iReturnValue = 1;
    goto cleanup;
}

// Save output file
if (!PdfOptimizeSaveAs(pOptimizer, szOutputPath, _T(""), _T(""), ePermNoEncryption))
{
    _tprintf(_T("Output file %s cannot be created. %s (ErrorCode: 0x%08x).\n"), szOutputPath,
        PdfOptimizeGetErrorMessage(pOptimizer), PdfOptimizeGetErrorCode(pOptimizer));
    iReturnValue = 1;
    goto cleanup;
}

// Close input file
if (!PdfOptimizeClose(pOptimizer))
{
    _tprintf(_T("Input file %s cannot be closed. %s (ErrorCode: 0x%08x).\n"), szInputPath, 
        PdfOptimizeGetErrorMessage(pOptimizer), PdfOptimizeGetErrorCode(pOptimizer));
    iReturnValue = 1;
    goto cleanup;
}

PDF Dokument für den Druck optimieren

Vermeide drucktechnische Probleme mit PDF Dokumenten. Reduziere die Gesamtdateigrösse und führe Schriftarten und Schriftprogramme zusammen, um kleinere Spooldateien zu erstellen und den Speicherverbrauch des Druckers zu reduzieren. Konvertiere Farben in CMYK. Entferne oder ändere keine Informationen, wie z.B. die Bildauflösung, die für eine klar definierte Wiedergabe erforderlich sind.

C# Beispiel:
// Create the optimizer
using (Optimizer optimizer = new Optimizer())
{
    // Choose the optimization profile for printing
    optimizer.Profile = PDFOptimizationProfile.eOptimizationProfilePrint;

    // Open input file
    if (!optimizer.Open(inputPath, ""))
        throw new Exception(String.Format("Input file {0} cannot be opened. " + 
            "{1} (ErrorCode: 0x{2:x}).", inputPath, optimizer.ErrorMessage, optimizer.ErrorCode));

    // Save output file
    if (!optimizer.SaveAs(outputPath, "", "", PDFPermission.ePermNoEncryption))
        throw new Exception(String.Format("Output file {0} cannot be created. {1} " + 
                "(ErrorCode: 0x{2:x}).", outputPath, optimizer.ErrorMessage, optimizer.ErrorCode));

    // Close input file
    if (!optimizer.Close())
        throw new Exception(String.Format("Input file {0} cannot be closed. {1} " + 
                "(ErrorCode: 0x{2:x}).", inputPath, optimizer.ErrorMessage, optimizer.ErrorCode));
}
Java Beispiel:
// Create the optimizer
optimizer = new PdfOptimize();

// Choose the optimization profile for printing 
optimizer.setProfile(PdfOptimize.OPTIMIZATIONPROFILE.eOptimizationProfilePrint);

// Open input file
if (!optimizer.open(inputPath, ""))
    throw new IOException(String.format("Input file %s cannot be opened. %s (ErrorCode: 0x%08x).",
        inputPath, optimizer.getErrorMessage(), optimizer.getErrorCode()));

// Save output file 
if (!optimizer.saveAs(outputPath, "", "", NativeLibrary.PERMISSION.ePermNoEncryption))
    throw new IOException(String.format("Output file %s cannot be created. %s (ErrorCode: 0x%08x).",
        outputPath, optimizer.getErrorMessage(), optimizer.getErrorCode()));

// Close input file
if (!optimizer.close())
    throw new IOException(String.format("Input file %s cannot be closed. %s (ErrorCode: 0x%08x).",
        inputPath, optimizer.getErrorMessage(), optimizer.getErrorCode()));
C Beispiel:
// Create the optimizer
pOptimizer = PdfOptimizeCreateObject();

// Choose the optimization profile for printing
PdfOptimizeSetProfile(pOptimizer, eOptimizationProfilePrint);

// Open input file
if (!PdfOptimizeOpen(pOptimizer, szInputPath, _T("")))
{
    _tprintf(_T("Input file %s cannot be opened. %s (ErrorCode: 0x%08x).\n"), szInputPath,
        PdfOptimizeGetErrorMessage(pOptimizer), PdfOptimizeGetErrorCode(pOptimizer));
    iReturnValue = 1;
    goto cleanup;
}

// Save output file
if (!PdfOptimizeSaveAs(pOptimizer, szOutputPath, _T(""), _T(""), ePermNoEncryption))
{
    _tprintf(_T("Output file %s cannot be created. %s (ErrorCode: 0x%08x).\n"), szOutputPath,
        PdfOptimizeGetErrorMessage(pOptimizer), PdfOptimizeGetErrorCode(pOptimizer));
    iReturnValue = 1;
    goto cleanup;
}

// Close input file
if (!PdfOptimizeClose(pOptimizer))
{
    _tprintf(_T("Input file %s cannot be closed. %s (ErrorCode: 0x%08x).\n"), szInputPath,
        PdfOptimizeGetErrorMessage(pOptimizer), PdfOptimizeGetErrorCode(pOptimizer));
    iReturnValue = 1;
    goto cleanup;
}

PDF Dokument für das Web optimieren

Verringere die Dateigrösse eines PDFs, um den Speicherbedarf auf einem Webserver und die Downloadzeiten zu reduzieren. Diese Optimierung kann zu geringen visuellen Verlusten führen. Das Ausgabe PDF ist linearisiert, was bedeutet, dass geeignete Viewer Inhalte anzeigen können, bevor das gesamte Dokument heruntergeladen ist.

C# Beispiel:
// Create the optimizer
using (Optimizer optimizer = new Optimizer())
{
    // Choose the optimization profile for web/e-mail
    optimizer.Profile = PDFOptimizationProfile.eOptimizationProfileWeb;

    // Disable auto-linearization
    optimizer.AutoLinearize = false;

    // Set linearization
    optimizer.Linearize = linearize;

    // Open input file
    if (!optimizer.Open(inputPath, ""))
        throw new Exception(String.Format("Input file {0} cannot be opened. " +
            "{1} (ErrorCode: 0x{2:x}).", inputPath, optimizer.ErrorMessage, optimizer.ErrorCode));

    // Save output file
    if (!optimizer.SaveAs(outputPath, "", "", PDFPermission.ePermNoEncryption))
        throw new Exception(String.Format("Output file {0} cannot be created. " +
            "{1} (ErrorCode: 0x{2:x}).", outputPath, optimizer.ErrorMessage, optimizer.ErrorCode));

    // Close input file
    if (!optimizer.Close())
        throw new Exception(String.Format("Input file {0} cannot be closed. " +
            "{1} (ErrorCode: 0x{2:x}).", inputPath, optimizer.ErrorMessage, optimizer.ErrorCode));
}
Java Beispiel:
// Create the optimizer
optimizer = new PdfOptimize();

// Choose the optimization profile for web/e-mail
optimizer.setProfile(PdfOptimize.OPTIMIZATIONPROFILE.eOptimizationProfileWeb);

// Disable auto-linearization
optimizer.setAutoLinearize(false);

// Set linearization
optimizer.setLinearize(linearize);

// Open input file
if (!optimizer.open(inputPath, ""))
    throw new IOException(String.format("Input file %s cannot be opened. %s (ErrorCode: 0x%08x).",
        inputPath, optimizer.getErrorMessage(), optimizer.getErrorCode()));

// Save output file 
if (!optimizer.saveAs(outputPath, "", "", NativeLibrary.PERMISSION.ePermNoEncryption))
    throw new IOException(String.format("Output file %s cannot be created. %s (ErrorCode: 0x%08x).",
        outputPath, optimizer.getErrorMessage(), optimizer.getErrorCode()));

// Close input file
if (!optimizer.close())
    throw new IOException(String.format("Input file %s cannot be closed. %s (ErrorCode: 0x%08x).",
        inputPath, optimizer.getErrorMessage(), optimizer.getErrorCode()));
C Beispiel:
// Create the optimizer
pOptimizer = PdfOptimizeCreateObject();

// Choose the optimization profile for web/e-mail
PdfOptimizeSetProfile(pOptimizer, eOptimizationProfileWeb);

// Disable auto-linearization
PdfOptimizeSetAutoLinearize(pOptimizer, 0);

// Set linearization
PdfOptimizeSetLinearize(pOptimizer, bLinearize);

// Open input file
if (!PdfOptimizeOpen(pOptimizer, szInputPath, _T("")))
{
    _tprintf(_T("Input file %s cannot be opened. %s (ErrorCode: 0x%08x).\n"), szInputPath,
        PdfOptimizeGetErrorMessage(pOptimizer), PdfOptimizeGetErrorCode(pOptimizer));
    iReturnValue = 1;
    goto cleanup;
}

// Save output file
if (!PdfOptimizeSaveAs(pOptimizer, szOutputPath, _T(""), _T(""), ePermNoEncryption))
{
    _tprintf(_T("Output file %s cannot be created. %s (ErrorCode: 0x%08x).\n"), szOutputPath,
        PdfOptimizeGetErrorMessage(pOptimizer), PdfOptimizeGetErrorCode(pOptimizer));
    iReturnValue = 1;
    goto cleanup;
}

// Close input file
if (!PdfOptimizeClose(pOptimizer))
{
    _tprintf(_T("Input file %s cannot be closed. %s (ErrorCode: 0x%08x).\n"), szInputPath,
        PdfOptimizeGetErrorMessage(pOptimizer), PdfOptimizeGetErrorCode(pOptimizer));
    iReturnValue = 1;
    goto cleanup;
}

Entfernung

Auflösen von Annotationen in PDF Dokumenten

Entferne die Interaktivität aller Annotationen. Dazu werden Annotationen und Formularfelder aus der internen PDF Datenstruktur entfernt und eine unveränderliche optische Darstellung an der entsprechenden Stelle als Ersatz eingesetzt.

C# Beispiel:
// Create the optimizer
using (Optimizer optimizer = new Optimizer())
{
    // Flatten and remove annotations and form fields
    optimizer.Strip = PDFStripType.eStripAnnots | PDFStripType.eStripFormsAnnots;

    // Open input file
    if (!optimizer.Open(inputPath, ""))
        throw new Exception(String.Format("Input file {0} cannot be opened. " +
            "{1} (ErrorCode: 0x{2:x}).", inputPath, optimizer.ErrorMessage, optimizer.ErrorCode));

    // Save output file
    if (!optimizer.SaveAs(outputPath, "", "", PDFPermission.ePermNoEncryption))
        throw new Exception(String.Format("Output file {0} cannot be created. " +
            "{1} (ErrorCode: 0x{2:x}).", outputPath, optimizer.ErrorMessage, optimizer.ErrorCode));

    // Close input file
    if (!optimizer.Close())
        throw new Exception(String.Format("Input file {0} cannot be closed. " +
            "{1} (ErrorCode: 0x{2:x}).", inputPath, optimizer.ErrorMessage, optimizer.ErrorCode));
}
Java Beispiel:
// Create the optimizer
optimizer = new PdfOptimize();

// Flatten and remove annotations and form fields 
optimizer.setStrip(NativeLibrary.STRIPTYPE.eStripAnnots | 
    NativeLibrary.STRIPTYPE.eStripFormsAnnots);

// Open input file
if (!optimizer.open(inputPath, "")) 
    throw new IOException(String.format("Input file %s cannot be opened. %s (ErrorCode: 0x%08x).",
        inputPath, optimizer.getErrorMessage(), optimizer.getErrorCode()));

// Save output file
if (!optimizer.saveAs(outputPath, "", "", NativeLibrary.PERMISSION.ePermNoEncryption)) 
    throw new IOException(String.format("Output file %s cannot be created. %s (ErrorCode: 0x%08x).",
        outputPath, optimizer.getErrorMessage(), optimizer.getErrorCode()));

// Close input file
if (!optimizer.close())
    throw new IOException(String.format("Input file %s cannot be closed. %s (ErrorCode: 0x%08x).",
        inputPath, optimizer.getErrorMessage(), optimizer.getErrorCode()));
C Beispiel:
// Create the optimizer
pOptimizer = PdfOptimizeCreateObject();

// Flatten and remove annotations and form fields
PdfOptimizeSetStrip(pOptimizer, eStripAnnots | eStripFormsAnnots);

// Open input file
if (!PdfOptimizeOpen(pOptimizer, szInputPath, _T("")))
{
    _tprintf(_T("Input file %s cannot be opened. %s (ErrorCode: 0x%08x).\n"), szInputPath, 
        PdfOptimizeGetErrorMessage(pOptimizer), PdfOptimizeGetErrorCode(pOptimizer));
    iReturnValue = 1;
    goto cleanup;
}

// Save output file
if (!PdfOptimizeSaveAs(pOptimizer, szOutputPath, _T(""), _T(""), ePermNoEncryption))
{
    _tprintf(_T("Output file %s cannot be created. %s (ErrorCode: 0x%08x).\n"), szOutputPath, 
        PdfOptimizeGetErrorMessage(pOptimizer), PdfOptimizeGetErrorCode(pOptimizer));
    iReturnValue = 1;
    goto cleanup;
}

// Close input file
if (!PdfOptimizeClose(pOptimizer))
{
    _tprintf(_T("Input file %s cannot be closed. %s (ErrorCode: 0x%08x).\n"), szInputPath, 
        PdfOptimizeGetErrorMessage(pOptimizer), PdfOptimizeGetErrorCode(pOptimizer));
    iReturnValue = 1;
    goto cleanup;
}

Zusätzliche Informationen aus PDF entfernen

Entferne zusätzliche Informationen aus einem PDF, die für viele Zwecke nicht erforderlich sind. Dazu gehören alternative Bilder, Metadaten, die Ausgabeabsicht, der Dokumentstrukturbaum und Miniaturansichten.

C# Beispiel:
// Create the optimizer
using (Optimizer optimizer = new Optimizer())
{
    // Configure which additional information to remove
    optimizer.Strip = PDFStripType.eStripAlternates | PDFStripType.eStripMetadata | 
        PDFStripType.eStripOutputIntents | PDFStripType.eStripStructTree | PDFStripType.eStripThumb;

    // Open input file
    if (!optimizer.Open(inputPath, ""))
        throw new Exception(String.Format("Input file {0} cannot be opened. " + 
            "{1} (ErrorCode: 0x{2:x}).", inputPath, optimizer.ErrorMessage, optimizer.ErrorCode));

    // Save output file
    if (!optimizer.SaveAs(outputPath, "", "", PDFPermission.ePermNoEncryption))
        throw new Exception(String.Format("Output file {0} cannot be created. " + 
            "{1} (ErrorCode: 0x{2:x}).", outputPath, optimizer.ErrorMessage, optimizer.ErrorCode));

    // Close input file
    if (!optimizer.Close())
        throw new Exception(String.Format("Input file {0} cannot be closed. " + 
            "{1} (ErrorCode: 0x{2:x}).", inputPath, optimizer.ErrorMessage, optimizer.ErrorCode));
}
Java Beispiel:
// Create the optimizer
optimizer = new PdfOptimize();

// Configure which additional information to remove
optimizer.setStrip(NativeLibrary.STRIPTYPE.eStripAlternates | 
    NativeLibrary.STRIPTYPE.eStripMetadata | NativeLibrary.STRIPTYPE.eStripOutputIntents | 
    NativeLibrary.STRIPTYPE.eStripStructTree | NativeLibrary.STRIPTYPE.eStripThumb);

// Open input file
if (!optimizer.open(inputPath, ""))
    throw new IOException(String.format("Input file %s cannot be opened. %s (ErrorCode: 0x%08x).",
        inputPath, optimizer.getErrorMessage(), optimizer.getErrorCode()));

// Save output file 
if (!optimizer.saveAs(outputPath, "", "", NativeLibrary.PERMISSION.ePermNoEncryption))
    throw new IOException(String.format("Output file %s cannot be created. %s (ErrorCode: 0x%08x).",
        outputPath, optimizer.getErrorMessage(), optimizer.getErrorCode()));

// Close input file
if (!optimizer.close())
    throw new IOException(String.format("Input file %s cannot be closed. %s (ErrorCode: 0x%08x).",
        inputPath, optimizer.getErrorMessage(), optimizer.getErrorCode()));
C Beispiel:
// Create the optimizer
pOptimizer = PdfOptimizeCreateObject();

// Remove additional information at one's option
PdfOptimizeSetStrip(pOptimizer, eStripAlternates | eStripMetadata | eStripOutputIntents | 
    eStripStructTree | eStripThumb);

// Open input file
if (!PdfOptimizeOpen(pOptimizer, szInputPath, _T("")))
{
    _tprintf(_T("Input file %s cannot be opened. %s (ErrorCode: 0x%08x).\n"), szInputPath,
        PdfOptimizeGetErrorMessage(pOptimizer), PdfOptimizeGetErrorCode(pOptimizer));
    iReturnValue = 1;
    goto cleanup;
}

// Save output file
if (!PdfOptimizeSaveAs(pOptimizer, szOutputPath, _T(""), _T(""), ePermNoEncryption))
{
    _tprintf(_T("Output file %s cannot be created. %s (ErrorCode: 0x%08x).\n"), szOutputPath,
        PdfOptimizeGetErrorMessage(pOptimizer), PdfOptimizeGetErrorCode(pOptimizer));
    iReturnValue = 1;
    goto cleanup;
}

// Close input file
if (!PdfOptimizeClose(pOptimizer))
{
    _tprintf(_T("Input file %s cannot be closed. %s (ErrorCode: 0x%08x).\n"), szInputPath,
        PdfOptimizeGetErrorMessage(pOptimizer), PdfOptimizeGetErrorCode(pOptimizer));
    iReturnValue = 1;
    goto cleanup;
}

Funktionen und Konfiguration

Dokument mit Benutzer- oder Besitzerpasswort verschlüsseln

Erstelle ein verschlüsseltes Dokument, für dessen Öffnen ein Passwort erforderlich ist. Dem Benutzer ist es gestattet, unter Angabe des Benutzerkennworts Anmerkungen zu machen. Andererseits ist es dem Benutzer nicht gestattet, das Dokument zu drucken, zu kopieren oder zusammenzustellen. Der gesamte Bereich der Berechtigungen wird nur mit dem Eigentümerpasswort vergeben.

C# Beispiel:
// Create the optimizer
using (Optimizer optimizer = new Optimizer())
{
    // Open input file
    if (!optimizer.Open(inputPath, ""))
        throw new Exception(String.Format("Input file {0} cannot be opened. " +
            "{1} (ErrorCode: 0x{2:x}).", inputPath, optimizer.ErrorMessage, optimizer.ErrorCode));

    // Save output file, provide user and owner password
    if (!optimizer.SaveAs(outputPath, userPassword, ownerPassword, PDFPermission.ePermAnnotate))
        throw new Exception(String.Format("Output file {0} cannot be created. " +
            "{1} (ErrorCode: 0x{2:x}).", outputPath, optimizer.ErrorMessage, optimizer.ErrorCode));

    // Close input file
    if (!optimizer.Close())
        throw new Exception(String.Format("Input file {0} cannot be closed. " +
            "{1} (ErrorCode: 0x{2:x}).", inputPath, optimizer.ErrorMessage, optimizer.ErrorCode));
}
Java Beispiel:
// Create the optimizer
optimizer = new PdfOptimize();

// Open input file
if (!optimizer.open(inputPath, "")) 
    throw new IOException(String.format("Input file %s cannot be opened. %s (ErrorCode: 0x%08x).",
        inputPath, optimizer.getErrorMessage(), optimizer.getErrorCode()));

// Save output file, provide user and owner password
if (!optimizer.saveAs(outputPath, userPassword, ownerPassword,
    NativeLibrary.PERMISSION.ePermAnnotate)) throw new IOException(String.format("Output file %s " +
        "cannot be created. %s (ErrorCode: 0x%08x).", outputPath, optimizer.getErrorMessage(),
        optimizer.getErrorCode()));

// Close input file
if (!optimizer.close())
    throw new IOException(String.format("Input file %s cannot be closed. %s (ErrorCode: 0x%08x).",
        inputPath, optimizer.getErrorMessage(), optimizer.getErrorCode()));
C Beispiel:
// Create the optimizer
pOptimizer = PdfOptimizeCreateObject();

// Open input file
if (!PdfOptimizeOpen(pOptimizer, szInputPath, _T("")))
{
    _tprintf(_T("Input file %s cannot be opened. %s (ErrorCode: 0x%08x).\n"), szInputPath,
        PdfOptimizeGetErrorMessage(pOptimizer), PdfOptimizeGetErrorCode(pOptimizer));
    iReturnValue = 1;
    goto cleanup;
}

// Save output file, provide user and owner password
if (!PdfOptimizeSaveAs(pOptimizer, szOutputPath, _T(szUserPassword), _T(szOwnerPassword),
    ePermAnnotate))
{
    _tprintf(_T("Output file %s cannot be created.  %s (ErrorCode: 0x%08x).\n"), szOutputPath,
        PdfOptimizeGetErrorMessage(pOptimizer), PdfOptimizeGetErrorCode(pOptimizer));
    iReturnValue = 1;
    goto cleanup;
}

// Close input file
if (!PdfOptimizeClose(pOptimizer))
{
    _tprintf(_T("Input file %s cannot be closed. %s (ErrorCode: 0x%08x).\n"), szInputPath, 
        PdfOptimizeGetErrorMessage(pOptimizer), PdfOptimizeGetErrorCode(pOptimizer));
    iReturnValue = 1;
    goto cleanup;
}

Extrahiere Bildern und Schriftarten aus PDF Dateien

Extrahiere alle eingebetteten Bilder und Schriftartendateien und speichere sie als Dateien. Je nach Schriftart und Kompressionstyp eines Bildes haben die extrahierten Dateien unterschiedliche Formate.

C# Beispiel:
// Create the optimizer
using (Optimizer optimizer = new Optimizer())
{
    // Set extract fonts and images
    optimizer.ExtractFonts = true;
    optimizer.ExtractImages = true;

    // Open input file
    if (!optimizer.Open(inputPath, ""))
        throw new Exception(String.Format("Input file {0} cannot be opened. " +
            "{1} (ErrorCode: 0x{2:x}).", inputPath, optimizer.ErrorMessage, optimizer.ErrorCode));

    // Extract fonts and images
    if (!optimizer.SaveAs(outputPath, "", "", PDFPermission.ePermNoEncryption))
        throw new Exception(String.Format("Fonts and images could not be extracted. " +
            "{0} (ErrorCode: 0x{1:x}).", optimizer.ErrorMessage, optimizer.ErrorCode));

    // Close input file
    if (!optimizer.Close())
        throw new Exception(String.Format("Input file {0} cannot be closed. " +
            "{1} (ErrorCode: 0x{2:x}).", inputPath, optimizer.ErrorMessage, optimizer.ErrorCode));
}
Java Beispiel:
// Create the optimizer
optimizer = new PdfOptimize();

// Set extract fonts and images
optimizer.setExtractFonts(true);
optimizer.setExtractImages(true);

// Open input file
if (!optimizer.open(inputPath, "")) 
    throw new IOException(String.format("Input file %s cannot be opened. %s (ErrorCode: 0x%08x).",
        inputPath, optimizer.getErrorMessage(), optimizer.getErrorCode()));

// Extract fonts and images
if (!optimizer.saveAs(outputPath, "", "", NativeLibrary.PERMISSION.ePermNoEncryption)) 
    throw new IOException(String.format("Fonts and images could not be extracted. %s " +
        "(ErrorCode: 0x%08x).", outputPath, optimizer.getErrorMessage(), optimizer.getErrorCode()));

// Close input file
if (!optimizer.close())
    throw new IOException(String.format("Input file %s cannot be closed. %s (ErrorCode: 0x%08x).",
        inputPath, optimizer.getErrorMessage(), optimizer.getErrorCode()));
C Beispiel:
// Create the optimizer
pOptimizer = PdfOptimizeCreateObject();

// Set extract fonts and images
PdfOptimizeSetExtractFonts(pOptimizer, 1);
PdfOptimizeSetExtractImages(pOptimizer, 1);

// Open input file
if (!PdfOptimizeOpen(pOptimizer, szInputPath, _T("")))
{
    _tprintf(_T("Input file %s cannot be opened. %s (ErrorCode: 0x%08x).\n"), szInputPath, 
        PdfOptimizeGetErrorMessage(pOptimizer), PdfOptimizeGetErrorCode(pOptimizer));
    iReturnValue = 1;
    goto cleanup;
}

// Extract fonts and images 
if (!PdfOptimizeSaveAs(pOptimizer, szOutputPath, _T(""), _T(""), ePermNoEncryption))
{
    _tprintf(_T("Fonts and images cannot be extracted. %s (ErrorCode: 0x%08x).\n"), 
        PdfOptimizeGetErrorMessage(pOptimizer), PdfOptimizeGetErrorCode(pOptimizer));
    iReturnValue = 1;
    goto cleanup;
}

// Close input file
if (!PdfOptimizeClose(pOptimizer))
{
    _tprintf(_T("Input file %s cannot be closed. %s (ErrorCode: 0x%08x).\n"), szInputPath, 
        PdfOptimizeGetErrorMessage(pOptimizer), PdfOptimizeGetErrorCode(pOptimizer));
    iReturnValue = 1;
    goto cleanup;
}

Dokumentinfo eines PDF Dokuments festlegen

Lege die Metadaten der Dokumentinfo eines PDF Dokuments fest, wie Titel, Autor, Betreff, Ersteller und Produzent.

C# Beispiel:
// Create the optimizer
using (Optimizer optimizer = new Optimizer())
{
    // Set author, title, subject, creator and producer of PDF
    optimizer.SetInfoEntry("Author", author);
    optimizer.SetInfoEntry("Title", title);
    optimizer.SetInfoEntry("Subject", subject);
    optimizer.SetInfoEntry("Creator", creator);
    optimizer.SetInfoEntry("Producer", producer);

    // Open input file
    if (!optimizer.Open(inputPath, ""))
        throw new Exception(String.Format("Input file {0} cannot be opened. " + 
            "{1} (ErrorCode: 0x{2:x}).", inputPath, optimizer.ErrorMessage, optimizer.ErrorCode));

    // Save output file
    if (!optimizer.SaveAs(outputPath, "", "", PDFPermission.ePermNoEncryption))
        throw new Exception(String.Format("Output file {0} cannot be created. " + 
            "{1} (ErrorCode: 0x{2:x}).", outputPath, optimizer.ErrorMessage, optimizer.ErrorCode));

    // Close input file
    if (!optimizer.Close())
        throw new Exception(String.Format("Input file {0} cannot be closed. " + 
            "{1} (ErrorCode: 0x{2:x}).", inputPath, optimizer.ErrorMessage, optimizer.ErrorCode));
}
Java Beispiel:
// Create the optimizer
optimizer = new PdfOptimize();

// Set author, title, creator and producer of PDF 
optimizer.setInfoEntry("Author", author);
optimizer.setInfoEntry("Title", title);
optimizer.setInfoEntry("Subject", subject);
optimizer.setInfoEntry("Creator", creator);
optimizer.setInfoEntry("Producer", producer);

// Open input file
if (!optimizer.open(inputPath, ""))
    throw new IOException(String.format("Input file %s cannot be opened. %s (ErrorCode: 0x%08x).",
        inputPath, optimizer.getErrorMessage(), optimizer.getErrorCode()));

// Save output file 
if (!optimizer.saveAs(outputPath, "", "", NativeLibrary.PERMISSION.ePermNoEncryption))
    throw new IOException(String.format("Output file %s cannot be created. %s (ErrorCode: 0x%08x).",
        outputPath, optimizer.getErrorMessage(), optimizer.getErrorCode()));

// Close input file
if (!optimizer.close())
    throw new IOException(String.format("Input file %s cannot be closed. %s (ErrorCode: 0x%08x).",
        inputPath, optimizer.getErrorMessage(), optimizer.getErrorCode()));
C Beispiel:
// Create the optimizer
pOptimizer = PdfOptimizeCreateObject();

// Set author, title, subject, creator and producer of PDF
PdfOptimizeSetInfoEntry(pOptimizer, _T("Author"), _T(szAuthor));
PdfOptimizeSetInfoEntry(pOptimizer, _T("Title"), _T(szTitle));
PdfOptimizeSetInfoEntry(pOptimizer, _T("Subject"), _T(szSubject));
PdfOptimizeSetInfoEntry(pOptimizer, _T("Creator"), _T(szCreator));
PdfOptimizeSetInfoEntry(pOptimizer, _T("Producer"), _T(szProducer));

// Open input file
if (!PdfOptimizeOpen(pOptimizer, szInputPath, _T("")))
{
    _tprintf(_T("Input file %s cannot be opened. %s (ErrorCode: 0x%08x).\n"), szInputPath,
        PdfOptimizeGetErrorMessage(pOptimizer), PdfOptimizeGetErrorCode(pOptimizer));
    iReturnValue = 1;
    goto cleanup;
}

// Save output file
if (!PdfOptimizeSaveAs(pOptimizer, szOutputPath, _T(""), _T(""), ePermNoEncryption))
{
    printf(_T("Output file %s cannot be created. %s (ErrorCode: 0x%08x).\n"), szOutputPath,
        PdfOptimizeGetErrorMessage(pOptimizer), PdfOptimizeGetErrorCode(pOptimizer));
    iReturnValue = 1;
    goto cleanup;
}

// Close input file
if (!PdfOptimizeClose(pOptimizer))
{
    _tprintf(_T("Input file %s cannot be closed. %s (ErrorCode: 0x%08x).\n"), szInputPath,
        PdfOptimizeGetErrorMessage(pOptimizer), PdfOptimizeGetErrorCode(pOptimizer));
    iReturnValue = 1;
    goto cleanup;
}

Upgrade der PDF Version

Lege die minimale PDF Version für das Ausgabedokument fest. Die unterstützten Werte reichen von'1.1' bis'1.7'. Wenn die PDF-Version des Eingabedokuments höher als das Minimum ist, wird die Version des Eingabedokuments in das Ausgabedokument übernommen.

C# Beispiel:
// Create the optimizer
using (Optimizer optimizer = new Optimizer())
{
    // Set minimum version of output file
    if (!optimizer.SetVersion(version))
        throw new Exception(String.Format("The version {0} of the output file {1} cannot be set. " +
            "{2} (ErrorCode: 0x{3:x}).", version, outputPath, optimizer.ErrorMessage, 
            optimizer.ErrorCode));

    // Open input file
    if (!optimizer.Open(inputPath, ""))
        throw new Exception(String.Format("Input file {0} cannot be opened. " + 
            "{1} (ErrorCode: 0x{2:x}).", inputPath, optimizer.ErrorMessage, optimizer.ErrorCode));

    // Save output file
    if (!optimizer.SaveAs(outputPath, "", "", PDFPermission.ePermNoEncryption))
        throw new Exception(String.Format("Output file {0} cannot be created. " + 
            "{1} (ErrorCode: 0x{2:x}).", outputPath, optimizer.ErrorMessage, optimizer.ErrorCode));

    // Close input file
    if (!optimizer.Close())
        throw new Exception(String.Format("Input file {0} cannot be closed. " + 
            "{1} (ErrorCode: 0x{2:x}).", inputPath, optimizer.ErrorMessage, optimizer.ErrorCode));
}
Java Beispiel:
// Create the optimizer
optimizer = new PdfOptimize();

// Set minimum version of output file 
if (!optimizer.setVersion(version))
    throw new IOException(String.format("The version %s of the output file %s cannot be set. " + 
        "%s (ErrorCode: 0x%08x).", version, outputPath, optimizer.getErrorMessage(), 
        optimizer.getErrorCode()));

// Open input file
if (!optimizer.open(inputPath, ""))
    throw new IOException(String.format("Input file %s cannot be opened. %s (ErrorCode: 0x%08x).",
        inputPath, optimizer.getErrorMessage(), optimizer.getErrorCode()));

// Save output file 
if (!optimizer.saveAs(outputPath, "", "", NativeLibrary.PERMISSION.ePermNoEncryption))
    throw new IOException(String.format("Output file %s cannot be created. %s (ErrorCode: 0x%08x).",
        outputPath, optimizer.getErrorMessage(), optimizer.getErrorCode()));

// Close input file
if (!optimizer.close())
    throw new IOException(String.format("Input file %s cannot be closed. %s (ErrorCode: 0x%08x).",
        inputPath, optimizer.getErrorMessage(), optimizer.getErrorCode()));
C Beispiel:
// Create the optimizer
pOptimizer = PdfOptimizeCreateObject();

// Set minimum version 
if (!PdfOptimizeSetVersion(pOptimizer, szVersion))
{
    _tprintf(_T("The version %s of the output file %s cannot be set. %s (ErrorCode: 0x%08x).\n"),
        szVersion, szOutputPath, PdfOptimizeGetErrorMessage(pOptimizer),
        PdfOptimizeGetErrorCode(pOptimizer));
    iReturnValue = 1;
    goto cleanup;
}

// Open input file
if (!PdfOptimizeOpen(pOptimizer, szInputPath, _T("")))
{
    _tprintf(_T("Input file %s cannot be opened. %s (ErrorCode: 0x%08x).\n"), szInputPath,
        PdfOptimizeGetErrorMessage(pOptimizer), PdfOptimizeGetErrorCode(pOptimizer));
    iReturnValue = 1;
    goto cleanup;
}

// Save output file
if (!PdfOptimizeSaveAs(pOptimizer, szOutputPath, _T(""), _T(""), ePermNoEncryption))
{
    _tprintf(_T("Output file %s cannot be created. %s (ErrorCode: 0x%08x).\n"), szOutputPath,
        PdfOptimizeGetErrorMessage(pOptimizer), PdfOptimizeGetErrorCode(pOptimizer));
    iReturnValue = 1;
    goto cleanup;
}

// Close input file
if (!PdfOptimizeClose(pOptimizer))
{
    _tprintf(_T("Input file %s cannot be closed. %s (ErrorCode: 0x%08x).\n"), szInputPath,
        PdfOptimizeGetErrorMessage(pOptimizer), PdfOptimizeGetErrorCode(pOptimizer));
    iReturnValue = 1;
    goto cleanup;
}

In Memory

PDF im Speicher optimieren

Lese ein PDF aus einem Byte-Stream, optimiere es und gebe das Ergebnis als Byte-Stream zurück. Zu Demonstrationszwecken wird der PDF-Byte-Stream aus einer Datei erzeugt und der resultierende Byte-Stream wird in eine Datei zurückgeschrieben.

C# Beispiel:
// Create the optimizer
using (Optimizer optimizer = new Optimizer())
{
    // Open input buffer in-memory
    if (!optimizer.OpenMem(inputBuffer, ""))
        throw new Exception(String.Format("Input buffer cannot be opened in-memory. " +
            "{0} (ErrorCode: 0x{1:x}).", optimizer.ErrorMessage, optimizer.ErrorCode));

    // Save output file in-memory
    if (!optimizer.SaveInMemory())
        throw new Exception(String.Format("Output document cannot be saved in-memory. " +
            "{0} (ErrorCode: 0x{1:x}).", optimizer.ErrorMessage, optimizer.ErrorCode));

    // Close input file
    if (!optimizer.Close())
        throw new Exception(String.Format("Input file {0} cannot be closed. " +
            "{1} (ErrorCode: 0x{2:x}).", inputPath, optimizer.ErrorMessage, optimizer.ErrorCode));

    // Get PDF as buffer
    byte[] outputBuffer = optimizer.GetPdf();
    if (outputBuffer == null)
        throw new Exception(String.Format("Output file {0} cannot be created. " +
            "{1} (ErrorCode: 0x{2:x}).", outputPath, optimizer.ErrorMessage, optimizer.ErrorCode));

    // Write bytes to output file.
    File.WriteAllBytes(outputPath, outputBuffer);
}
Java Beispiel:
// Create the optimizer
optimizer = new PdfOptimize();

// Open input buffer in-memory
if (!optimizer.openMem(inputBuffer, ""))
    throw new IOException(String.format("Input buffer cannot be opened in-memory. " +
        "%s (ErrorCode: 0x%08x).", optimizer.getErrorMessage(), optimizer.getErrorCode()));

// Save output file in-memory
if (!optimizer.saveInMemory())
    throw new IOException(String.format("Output document cannot be saved in-memory. " + 
        "%s (ErrorCode: 0x%08x).", optimizer.getErrorMessage(), optimizer.getErrorCode()));

// Close input file
if (!optimizer.close())
    throw new IOException(String.format("Input file %s cannot be closed. %s (ErrorCode: 0x%08x).",
        inputPath, optimizer.getErrorMessage(), optimizer.getErrorCode()));

// Get PDF as buffer
byte[] outputBuffer = optimizer.getPdf();
if (outputBuffer == null)
    throw new IOException(String.format("Output file %s cannot be created. %s (ErrorCode: 0x%08x).",
        outputPath, optimizer.getErrorMessage(), optimizer.getErrorCode()));

// Write bytes to output file
Files.write(Paths.get(outputPath), outputBuffer, StandardOpenOption.CREATE_NEW);
C Beispiel:
// Create the optimizer
pOptimizer = PdfOptimizeCreateObject();

// Open input PDF from memory buffer
if (!PdfOptimizeOpenMem(pOptimizer, pInputBuffer, nLength, _T("")))
{
    _tprintf(_T("Input buffer cannot be opened in-memory. %s (ErrorCode: 0x%08x).\n"),
        PdfOptimizeGetErrorMessage(pOptimizer), PdfOptimizeGetErrorCode(pOptimizer));
    iReturnValue = 1;
    goto cleanup;
}

// Save output file in-memory
if (!PdfOptimizeSaveInMemory(pOptimizer))
{
    _tprintf(_T("Output document cannot be saved in-memory. %s (ErrorCode: 0x%08x).\n"),
        PdfOptimizeGetErrorMessage(pOptimizer), PdfOptimizeGetErrorCode(pOptimizer));
    iReturnValue = 1;
    goto cleanup;
}

// Close input file
if (!PdfOptimizeClose(pOptimizer))
{
    _tprintf(_T("Input file %s cannot be closed. %s (ErrorCode: 0x%08x).\n"), szInputPath,
        PdfOptimizeGetErrorMessage(pOptimizer), PdfOptimizeGetErrorCode(pOptimizer));
    iReturnValue = 1;
    goto cleanup;
}

// Create output file
if ((pOutputFile = _tfopen(szOutputPath, _T("wb"))) == NULL)
{
    _tprintf(_T("Output file %s cannot be created. %s (ErrorCode: 0x%08x).\n"), szOutputPath,
        PdfOptimizeGetErrorMessage(pOptimizer), PdfOptimizeGetErrorCode(pOptimizer));
    iReturnValue = 1;
    goto cleanup;
}

// Get the PDF as a memory buffer
pOutputBuffer = PdfOptimizeGetPdf(pOptimizer);
// Write bytes to output file
if (fwrite(pOutputBuffer->m_pData, 1, pOutputBuffer->m_nLength, pOutputFile) != pOutputBuffer->m_nLength)
{
    _tprintf(_T("Failed to write data to output file %s.\n"), szOutputPath);
    iReturnValue = 1;
    goto cleanup;
}
fclose(pOutputFile);
pOutputFile = NULL;