THotPDF.CompressLoadedDocument

THotPDF

 

Top  Previous  Next

Compresses a loaded PDF: the parameterless form recompresses unfiltered streams, whilst the form with options runs every lossless size reduction HotPDF has to offer

 

Delphi syntax:

function CompressLoadedDocument: Integer; overload;

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

 

Description

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

Takes CompressionLevel to pick 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 wherever the font allows), recompresses streams with FlateDecode when that is smaller, and makes the next save use object streams. Images are neither resampled nor 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 carrying signature fields and changes nothing; set AllowSignatureInvalidation to compress it anyway

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

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

 

See also: THotPDF, OptimizeLoadedStreams, SubsetLoadedFonts, CompressDocument