CompressContent

Document properties

Description

Compresses every page content stream in the currently selected document. The Flate (zlib) algorithm is used so the resulting streams carry a /FlateDecode filter when the document is saved. Already-compressed streams are left untouched.

On Windows, the bundled zlib-ng backend is used in zlib-compatible mode. Win64 builds link the bcc64x zlib-ng runtime SIMD object set; Win32 keeps the compatibility-focused generic object set. Existing Delphi, ActiveX, DLL, and C++Builder code does not need any source changes.

Syntax

Delphi

function TPDFlib.CompressContent: Integer;

ActiveX

Function PDFlib::CompressContent As Long

DLL

int DLCompressContent(int InstanceID);

Return values

0No document is open or compression failed.
1Page content streams were compressed successfully.

Remarks

This is a document-wide operation. Use CompressPage if you only need to compress the currently selected page. To control whether newly added images and fonts are stored compressed, use CompressImages and CompressFonts respectively.

Run this once before SaveToFile when shrinking a freshly built document; the savings are typically large on text-heavy pages and negligible on pages that consist mostly of pre-compressed image data.

Example

// Build a document, compress everything, then save
PDF.NewDocument;
PDF.AddStandardFont('Helvetica');
PDF.AddPage;
PDF.PrintText(50, 750, 'Compressed document');

PDF.CompressContent;                   // page streams -> /FlateDecode
PDF.CompressImages(1);                 // also flate-encode any subsequent images
PDF.SaveToFile('compressed.pdf');

See also

CompressPage, CompressImages, CompressFonts, SaveToFile