THotPDF.CompressLoadedDocument

THotPDF

 

Top  Previous  Next

Compresses a loaded PDF: the parameterless form recompresses unfiltered streams, and the form with options runs every lossless size reduction HotPDF offers

 

Delphi syntax:

function CompressLoadedDocument: Integer; overload;

function CompressLoadedDocument(const Options: THPDFLoadedDocumentCompressionOptions; out AInfo: THPDFLoadedDocumentCompressionInfo): Integer; overload;

 

Description

The parameterless form returns the number of streams whose compressed payload was adopted

Uses CompressionLevel to select fastest, default, or maximum zlib compression; clNone leaves the document unchanged

Processes each source stream in bounded chunks and replaces it only when the compressed payload is smaller

Streams that already have a /Filter, deleted streams, and empty streams are left untouched

This compatibility helper delegates to OptimizeLoadedStreams with only lsffUnfiltered selected and a one-byte savings threshold

Call SaveLoadedDocument after compression to write the transformed object graph

 

With options

The form with options runs these steps in order, each one lossless: it drops unused page resources, merges identical fonts and Form XObjects, subsets the embedded fonts (compact subsets where the font allows it), recompresses streams with FlateDecode when that is smaller, and makes the next save use object streams. Images are not resampled or recompressed. The result is the number of rewritten objects, and AInfo reports each step

Every step rewrites bytes a signature covers, so by default the call refuses a document that carries signature fields and changes nothing; set AllowSignatureInvalidation to compress it anyway

A three-page document of English and Chinese text that embeds full Arial and SimSun fonts drops from about 10 MB to about 20 KB

Doc.LoadFromFile('input.pdf');
        Doc.CompressLoadedDocument(THPDFLoadedDocumentCompressionOptions.Default, Info);
        Doc.SaveLoadedDocument('output.pdf');

 

See also: THotPDF, OptimizeLoadedStreams, SubsetLoadedFonts, CompressDocument