CompressImages

Image handling, Document properties

Description

Sets the default compression mode applied to raw raster image data added to the document after this call. The setting affects images whose pixels are uploaded uncompressed (BMP, raw pixel arrays); images that are already compressed (JPEG, JPEG 2000, CCITT, JBIG2) keep their existing encoding and are stored as-is, since recompressing them would inflate the file and degrade quality.

Syntax

Delphi

function TPDFlib.CompressImages(Compress: Integer): Integer;

ActiveX

Function PDFlib::CompressImages(Compress As Long) As Long

DLL

int DLCompressImages(int InstanceID, int Compress);

Parameters

Compress0 — store raw raster images uncompressed.
1 — flate-compress raw raster images (/FlateDecode filter).

Return values

0The Compress parameter was out of range.
1The image-compression setting was updated.

Remarks

The setting only affects images added after the call. The default is to compress. Turning compression off is occasionally useful when integrating with a downstream renderer that does not support flate-decoded image streams; under normal use, leave compression enabled.

Flate compression is loss-less. For lossy JPEG compression of a raw raster image, encode the source to JPEG before adding it and use AddImageFromFile or AddImageFromStream — the JPEG byte stream is then embedded directly with a /DCTDecode filter.

Example

// Compress raw bitmaps but leave the pre-encoded JPEG as-is
PDF.CompressImages(1);
PDF.AddImageFromFile('logo.bmp');        // BMP -> flate compressed
PDF.AddImageFromFile('photo.jpg');       // JPEG bytes embedded directly (DCT)
PDF.AddImageFromFile('chart.png');       // PNG decoded -> flate compressed

See also

CompressContent, CompressFonts, AddImageFromFile, AddImageFromStream