ExternalizeInlineImages

Document optimization, image handling, performance

Description

Finds byte-identical supported inline images in selected page content and replaces their repeated BI through EI definitions with references to one shared Image XObject

Syntax

Delphi

Function TPDFlib.ExternalizeInlineImages(Const PageRange: WideString= ''; MinimumOccurrences: Integer= 2): Integer;

Parameters

PageRangeA 1-based page range such as 1,3,5-7, or an empty string for every page; duplicate page numbers are ignored
MinimumOccurrencesThe minimum number of exact occurrences required for promotion and must be at least 2

Return values

The number of inline image occurrences replaced, or 0 when no group qualifies, the range is invalid, the minimum is below 2, or the operation is cancelled before application

Remarks

Grouping includes dimensions, bit depth, image-mask and interpolation flags, colour space, filter chain, decode parameters, decode array and encoded payload, with SHA-256 indexing followed by exact comparison

Direct DeviceGray, DeviceRGB and DeviceCMYK images and stencil masks are supported; named or complex colour spaces and unknown inline dictionary entries remain unchanged

Existing filters and decode parameters are preserved; an unfiltered payload is Flate-compressed only when the compressed representation is smaller

A group is promoted only when a conservative estimate including the Image XObject, page resources and replacement instructions is smaller than the original inline spans

The operation reports collection and application progress, responds to Abort at page boundaries, restores the previously selected page and is idempotent

Cancellation during collection makes no changes; cancellation during application retains pages that were already completed

Example

ReplacedImages:= PDF.ExternalizeInlineImages('1-200', 3);
Writeln(ReplacedImages);

See also

OptimizeImages, RecompressStreams, NormalizeContentStreams