Class PdfOptimizer
- Namespace
- SoftZenPdf.Optimizer
- Assembly
- SoftZenPdf.Optimizer.dll
Makes PDFs smaller. Add the optimizations you want with AddOptimizationHandler(OptimizationHandler), then call
Optimize. The output is a complete new file: unused objects and earlier revisions are dropped, and the
input's encryption, passwords and permissions are kept.
public sealed class PdfOptimizer
- Inheritance
-
PdfOptimizer
- Inherited Members
Examples
var optimizer = new PdfOptimizer();
optimizer.AddOptimizationHandler(new CompressionOptimizer());
var result = optimizer.Optimize("input.pdf", "output.pdf");
Console.WriteLine($"Saved {result.Reduction:P0}");
Properties
- Handlers
The handlers, in the order they run.
- KeepOriginalIfNotSmaller
When the optimized file would not be smaller than the input, write the input unchanged instead and report KeptOriginal. Defaults to true. Evaluation copies are always written optimized, with the evaluation banner.
- Linearize
Writes the output linearized ("fast web view", ISO 32000-1 Annex F), so a browser or viewer can show the first page while the rest downloads. Linearized files use a cross-reference table rather than object streams, so this overrides UseObjectStreams, and the original is only kept by KeepOriginalIfNotSmaller when it was already linearized. Defaults to false.
Methods
- AddOptimizationHandler(OptimizationHandler)
Adds an optimization. Handlers run in the order they are added.
- Optimize(FileInfo, FileInfo, string?)
Optimizes a PDF file.
- Optimize(Stream, Stream, string?)
Optimizes a PDF read from a stream and writes the result to another stream.
- Optimize(string, string, string?)
Optimizes a PDF file.