THotPDF.CompressDocument

THotPDF

 

Properties  CompactFontSubsetting  EnableFontSubsetting

Turns on every writer option that makes the document smaller, with one switch.

 

Delphi syntax:

property CompressDocument: Boolean;

 

C++ syntax:

__property bool CompressDocument;

 

Description

Set CompressDocument to true before BeginDoc to write the next document as small as HotPDF can make it without changing how it looks. For that document, BeginDoc turns on:

  • FlateDecode compression of page content and other streams, at the maximum compression level
  • A cross-reference stream with object streams, which packs 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 each embedded font keeps only the glyphs the document shows

Object streams need PDF 1.5. When Version is older, it is raised to PDF 1.5 unless the version is locked; PDF/A-1 output keeps its classic cross-reference table, as the standard requires

 

CompressDocument does not change the settings you chose. EndDoc restores the values of Compression, CompressionLevel, UseXRefStream, UseObjectStreams, EnableFontSubsetting, CompactFontSubsetting, the objects-per-container limit and the version raise when the document is written, so the next document without CompressDocument is written as before. Images keep their own compression settings; nothing is resampled or recompressed with loss

 

The property is off by default. A three-page document of mixed English and Chinese text in Arial and SimSun drops from about 10 MB to about 20 KB, most of it from font subsetting. The trade-off is that the output is harder to edit later: subset fonts cannot show characters the document does not use, and compressed object streams are not readable 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