DownsampleImages
Document Management, Images
Description
Reduces the resolution of embedded image XObjects whose effective resolution exceeds MaxDPI. Each candidate image is decoded, resampled with its aspect ratio preserved, and re-encoded as DCTDecode (JPEG) when Quality is greater than 0 or as lossless FlateDecode (PNG) when Quality is 0; the image stream, /Filter, /Width, and /Height entries are rewritten in place
Syntax
Delphi
Function TPDFlib.DownsampleImages(MaxDPI, Quality, Filter: Integer): Integer;Parameters
| MaxDPI | Resolution threshold in DPI; images whose estimated effective resolution is above this value are resampled. Values below 24 abort the call |
|---|---|
| Quality | JPEG compression quality between 1 and 100 used for re-encoding; pass 0 to re-encode losslessly as PNG |
| Filter | 0 selects the box filter, which averages source pixel blocks; any other value selects bilinear resampling |
Return values
The number of image XObjects rewritten, or 0 when MaxDPI is below 24 or no image exceeded the threshold
Remarks
Effective resolution is estimated from the declared pixel width of the image against a Letter-width page, so the pass is conservative and print-quality images are left alone when in doubt
Images smaller than 8 x 8 declared pixels, images that fail to decode, and images whose resampled size would not be smaller than the original are skipped without failing the call
Example
PDF.LoadFromFile('scan.pdf', '');
PDF.DownsampleImages(150, 80, 0);
PDF.SaveToFile('scan-compressed.pdf');