PdfOptimizer Class

Makes documents smaller or removes what they do not need, in two steps: PdfOptimizer.CreatePlan lists the changes without making them, and PdfOptimizer.Apply makes the changes of the plan that are enabled.

public static class PdfOptimizer

Remarks

The changes are made to the document model: save the document to write them. A full save writes only the objects reachable from the trailer, so the removed objects are not written.

Methods

NameDescription
Apply(PdfOptimizationPlan)Makes the enabled changes of a plan.
CreatePlan(PdfDocument, PdfOptimizationOptions)Lists the changes the options ask for, without changing the document.

Apply(PdfOptimizationPlan)

PdfOptimizer.cs

Makes the enabled changes of a plan.

Parameters

plan PdfOptimizationPlan
The plan, from PdfOptimizer.CreatePlan.

Returns

IReadOnlyList<PdfOptimizationAction> The actions that changed the document; an action whose target was already removed (by another action, or since the plan was created) does not.

Exceptions

InvalidOperationException
The plan invalidates signatures, and PdfOptimizationOptions.AllowSignatureInvalidation is false.
PdfException
The document cannot be read.

CreatePlan(PdfDocument, PdfOptimizationOptions)

PdfOptimizer.cs

Lists the changes the options ask for, without changing the document.

public static PdfOptimizationPlan CreatePlan(PdfDocument document, PdfOptimizationOptions options)

Parameters

document PdfDocument
The document.
options PdfOptimizationOptions
The changes to plan.

Returns

PdfOptimizationPlan The plan.

Exceptions

PdfException
The document cannot be read.