PDFium Delphi Component Docs

SaveAsFlateRecompressed method

Component: TPdf  ·  Unit: PDFium
Rewrites the document and re-encodes eligible FlateDecode streams at maximum compression, replacing a stream only when the measured byte saving clears a caller threshold

Syntax

function SaveAsFlateRecompressed(Stream: TStream; const Options: TPdfFlateRecompressOptions; out Report: TPdfFlateRecompressReport; AllowSignedDocument: Boolean = False): Boolean;

function SaveAsFlateRecompressed(const FileName: string; const Options: TPdfFlateRecompressOptions; out Report: TPdfFlateRecompressReport; AllowSignedDocument: Boolean = False): Boolean;

Description

PDFium first writes a non-incremental copy of the current in-memory document, then the wrapper performs a document-wide reachability walk exactly like SaveAsReachable

Each reachable FlateDecode stream is decoded with PdfInflate and re-encoded with DeflateCompress at maximum compression; only streams whose measured saving clears both MinSavingBytes and MinSavingRatio are replaced

Object numbers and generations stay stable, so only the recompressed stream payloads and their direct /Length values change; every surviving cross-reference remains valid without renumbering

The output is a single classic revision with the rebuilt trailer carrying /Root, /Info and /ID forward

Policies and limits

Example

Options.MinSavingBytes:= 64;
Options.MinSavingRatio:= 0.1;
Pdf.SaveAsFlateRecompressed('recompressed.pdf', Options, Report);
WriteLn('recompressed ', Report.RecompressedCount, ' streams');

See Also

SaveAsReachable, SaveAsDeduplicated, SaveAs