function SaveAsDeduplicated(Stream: TStream; out Report: TPdfDedupReport; AllowSignedDocument: Boolean = False): Boolean;
function SaveAsDeduplicated(const FileName: string; out Report: TPdfDedupReport; AllowSignedDocument: Boolean = False): Boolean;
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
TPdfDedupReport reports kept and pruned object counts plus per-category merged font, image and form XObject counts, with source and output byte sizes and a structured failure messageAllowSignedDocument is explicitly enabled because a full rewrite invalidates existing signature byte ranges
Pdf.SaveAsDeduplicated('deduplicated.pdf', Report);
WriteLn('merged ', Report.MergedImageCount, ' images');