PDFium Delphi Component Docs

OptimizeImages method

Component: TPdf  ·  Unit: PDFium
Downsamples page image objects whose effective placement DPI exceeds a caller-selected target, leaving the optimised document ready for SaveAs

Syntax

function OptimizeImages(const Options: TPdfImageOptimizeOptions; out Report: TPdfImageOptimizeReport): Boolean;

Description

Unlike the SaveAs* rewrites, OptimizeImages edits the current in-memory document through the native PDFium image-object API, matching the AddImage / GenerateContent editing model

Every page is walked and each image object's effective placement DPI is read from FPDFImageObj_GetImageMetadata; when max(horizontal, vertical) DPI / TargetDpi reaches MinDpiRatio, the image is downsampled

Downsampling measures local luminance detail, selects a box, bilinear, bicubic, Lanczos, or bilevel filter from scale, content class, and preferred quality, and writes the smaller same-format bitmap back with FPDFImageObj_SetBitmap

BGRA samples are accumulated in premultiplied-alpha space and unpremultiplied only at the destination pixel, preventing transparent colour fringes around resampled edges

Each touched page is committed with FPDFPage_GenerateContent; the caller then saves the optimised document with the usual SaveAs call

Policies and limits

Example

Options:= TPdfImageOptimizeOptions.Default;
Options.TargetDpi:= 150;
Options.ResampleFilter:= pirfAdaptive;
Options.MaxWorkingBytes:= 64 * 1024 * 1024;
Pdf.OptimizeImages(Options, Report);
WriteLn('downsampled ', Report.OptimizedCount, ' images');
Pdf.SaveAs('optimized.pdf');

See Also

SaveAs, AddImage, SaveAsDeduplicated