PDFium Delphi Component Docs

SaveAsDeduplicated method

Component: TPdf  ·  Unit: PDFium
Rewrites the document as a single clean revision that first sweeps unreachable objects and then collapses compatible fonts, images, and form XObjects onto one shared representative

Syntax

function SaveAsDeduplicated(Stream: TStream; out Report: TPdfDedupReport; AllowSignedDocument: Boolean = False): Boolean;

function SaveAsDeduplicated(const FileName: string; out Report: TPdfDedupReport; AllowSignedDocument: Boolean = False): Boolean;

Description

PDFium first writes a non-incremental copy of the current in-memory document, then the wrapper performs a document-wide reachability walk and drops every unreachable object exactly like SaveAsReachable

Fonts, images, and form XObjects are then fingerprinted: each candidate dictionary, its full reachable subgraph, and its raw stream payload are hashed recursively, so duplicates merge only when their entire content is identical

Every cross-reference that pointed at a merged-away duplicate is rewritten to the surviving representative, and object numbers and generations stay stable so every surviving cross-reference remains valid

The output is a single classic revision with no object streams and no cross-reference stream, and the rebuilt trailer carries /Root, /Info, and /ID forward

Policies and limits

Example

Pdf.SaveAsDeduplicated('deduplicated.pdf', Report);
WriteLn('merged ', Report.MergedImageCount, ' images');

See Also

SaveAsReachable, SaveAs, SaveAsNormalizedContent