THotPDF.CompressDocument

THotPDF

 

Properties  CompactFontSubsetting  EnableFontSubsetting

Switches on every writer option that shrinks the document, using a single property

 

Delphi syntax:

property CompressDocument: Boolean;

 

C++ syntax:

__property bool CompressDocument;

 

Description

Set CompressDocument to true before BeginDoc and the next document is written as small as HotPDF can manage without altering its appearance. For that document, BeginDoc switches on:

  • FlateDecode compression of page content and the other streams, at the highest compression level
  • A cross-reference stream together with object streams, packing most objects into compressed containers (ISO 32000-1 7.5.7 and 7.5.8); each container holds up to 250 objects instead of 100, since fewer, larger containers compress better. A limit set through ConfigureAdaptiveObjectStreamPacking is kept
  • Font subsetting, with compact font subsets, so that each embedded font retains only the glyphs the document actually shows

Object streams require PDF 1.5. If Version is older it moves up to PDF 1.5 unless the version is locked; PDF/A-1 output retains its classic cross-reference table, exactly as the standard demands

 

CompressDocument leaves the settings you chose untouched. Once the document has been written, EndDoc puts Compression, CompressionLevel, UseXRefStream, UseObjectStreams, EnableFontSubsetting, CompactFontSubsetting, the objects-per-container limit and the version raise back to their previous values, so the next document written without CompressDocument comes out as before. Images keep their own compression settings; nothing is resampled or lossily recompressed

 

The property is off by default. A three-page document mixing English and Chinese text in Arial and SimSun falls from roughly 10 MB to about 20 KB, with font subsetting doing most of that work. The trade-off is output that is harder to edit afterwards: subset fonts cannot display characters the document never uses, and compressed object streams cannot be read in a text editor

 

Example:

PDF.CompressDocument := True;
        PDF.BeginDoc;
        PDF.CurrentPage.SetFont('SimSun', [], 11);
        PDF.CurrentPage.TextOut(40, 80, 0, 'Compressed output');
        PDF.EndDoc;

 

See also: CompactFontSubsetting, EnableFontSubsetting, CompressLoadedDocument