RecompressStreams

Document properties, Optimisation

Description

Re-deflates every plain FlateDecode stream of the selected document at the current compression level, keeping the smaller encoding per stream.

Syntax

Delphi

Function TPDFlib.RecompressStreams: Integer;

Return values

0No document is selected or no stream became smaller.
NThe number of streams replaced with a smaller encoding.

Remarks

Only streams with a single bare /FlateDecode filter qualify; streams with prediction parameters, other filter chains and cross-reference streams keep their original bytes. Damaged streams are skipped because the source data must decode to a complete zlib stream before it is re-encoded. Independent streams run in bounded batches configured by SetOptimizationWorkers, whilst replacements are applied in object order for deterministic output. The operation reports progress and Abort stops between discovery and batch boundaries. Typical use pairs SetCompressionLevel(9) with this call before an archival save, which shrinks documents originally written at a fast compression level without touching their content.

Example

PDF.LoadFromFile('fast-written.pdf', '');
PDF.SetCompressionLevel(9);
Shrunk:= PDF.RecompressStreams;
PDF.SaveToFile('smaller.pdf');
PDF.SetCompressionLevel(0);

See also

SetCompressionLevel, CompressContent, DownsampleImages, AuditDocumentSpace