Add FPdfMerge to the uses clause to enable TPdfNavigationMergeHelper.MergeFilesWithNavigation, or call the global MergePdfFilesWithNavigation function with an explicit destination document
The helper stages native page imports, rebuilds hierarchical outlines, combines named destinations, remaps page links and independently reopens the result before replacing the caller document. When replacing named destinations, WritePdfNavigation also refreshes matching legacy catalog keys with the final destinations
TPdfNavigationMergeOptions configures the run; NativeOptions carries the underlying TPdfBatchMergeOptions forwarded to each staged page import, honoring the insertion point, progress events, cancellation token and CreateDestination flag while outlines are rebuilt by the helper itself
NavigationPolicy selects a TPdfMergeNavigationPolicy value: pmnPreserve retains source hierarchy; pmnGroupBySource adds a heading named after each source file
Titles, parent relationships, styles, colors, expanded branches, URI actions, remote GoTo (/GoToR) actions, launch (/Launch) actions and resolved internal page destinations are preserved; selected, repeated and reordered pages map to the first imported occurrence, remote GoTo target page numbers remain untouched by local page-insertion offsets, and internal destinations to omitted pages become headings
Existing destination outlines shift when pages are inserted; source files remain open with write sharing denied while navigation and native page imports are captured
Only stop-on-error merging is supported; signed destinations, unsupported outline actions and encrypted postprocessing are rejected with an error report, and failure or cancellation preserves the caller document
This API retains the existing native form policy; use FPdfFormMerge when you need advanced AcroForm field collision and resource handling
PreserveNamedDestinations and PreservePageLinks both default to True; setting either option to False skips that part of the additional navigation processing
Named destinations are read from both the legacy catalog /Dests dictionary and the /Names/Dests name tree, including hierarchical trees, indirect arrays, destination dictionaries containing /D and multi-hop symbolic named-destination aliases; when both forms define the same key, the name-tree value takes precedence
The result uses a balanced /Names/Dests tree and retains unrelated destination name trees such as /EmbeddedFiles; source trees unrelated to destinations are not imported by this helper
Keys retain their original PDF string bytes, including UTF-16BE encoding; the exact view mode and parameters are preserved, including /FitH null and /XYZ null 34 null
NamedDestinationPolicy selects the TPdfMergeNamedDestinationPolicy applied when imported keys are combined with existing destination keys
| Policy | Behavior |
|---|---|
pndReject | A source key that already exists in the destination rejects the whole transaction |
pndRename | The default policy keeps nonconflicting names and prefixes conflicting names with DestinationPrefix, which defaults to Imported_; further collisions use deterministic prefixes such as 2_Imported_Shared |
pndNamespace | Every source key is prefixed with DestinationPrefix, its one-based source index and an underscore, such as Imported_1_Shared; remaining collisions receive a deterministic numeric prefix |
DestinationPrefix must contain 1 to 256 printable ASCII characters; prefixes are inserted after a UTF-16BE BOM when a key uses that encoding
Internal link annotations using /Dest or a /A /GoTo action preserve symbolic named-destination keys across pndRename and pndNamespace renames when named-destination replacement is active, and fall back to explicit page destinations when only page links are rewritten
Existing link owner pages and targets shift when pages are inserted; each occurrence of a repeatedly imported page receives an independent link annotation, while its internal targets map to the first selected occurrence of the target page
Destinations whose target page was omitted are removed from the named-destination tree; an affected link has its /Dest or GoTo action removed while retaining the annotation and its other properties
URI links remain intact; /GoToR remote destination links, /Launch application/file links, standard /Named navigation links (NextPage, PrevPage, FirstPage, LastPage) and chained /Next action sequences (single action dictionaries or action arrays combining /GoTo, /GoToR, /Launch, /Named and /URI) are captured, remapped across page insertions, written as indirect action chains and verified across reopen
Malformed or cyclic destination trees, unavailable object references and duplicate name-tree keys reject the transaction; failure, cancellation or an exceeded budget leaves the caller document unchanged
MaxOutlineItems, MaxOutlineDepth, MaxTitleCharacters, MaxNamedDestinations and MaxPageLinks default to 10,000 outline items, depth 128, 1,048,576 title characters, 10,000 named destinations and 100,000 page links; MaxDocumentBytes defaults to 256 MiB of document bytes and must stay positive without exceeding MaxInt
TPdfNavigationMergeOptions.Default returns those budget values together with NativeOptions from TPdfBatchMergeOptions.Default, pmnPreserve navigation, pndRename conflict handling with the Imported_ prefix, and both PreserveNamedDestinations and PreservePageLinks enabled
When additional destination or link processing is enabled, the maximum configured depth is 256, the named-destination limit must not exceed 65,536 and the page-link limit must not exceed 1,000,000; source capture also limits raw key bytes to 1 MiB
Combined named keys use a separate byte budget equal to MaxTitleCharacters; each source is captured within the configured budgets before selected-page filtering
PreservedNamedDestinationCount counts final named destinations, RenamedNamedDestinationCount counts imported keys changed by the selected policy and RemovedNamedDestinationCount counts unresolved or omitted named targets
RemappedPageLinkCount counts final internal destinations across both existing and imported links, and RemovedPageLinkCount counts removed internal destinations; a link containing both /Dest and GoTo contributes once for each destination
TPdfNavigationMergeReport records the outcome: Succeeded is set once the caller document has been replaced by the verified result, Cancelled marks a cancellation through the native cancellation token and ErrorMessage carries the failure text
ImportedSourceCount and ImportedPageCount total the imported sources and added pages, PreservedOutlineCount counts the outline nodes kept from the destination and the sources, and SourceGroupCount counts the headings introduced by pmnGroupBySource
RemovedDestinationCount counts outline destinations dropped because their target page was not imported
type
TPdfMergeNavigationPolicy= (pmnPreserve, pmnGroupBySource);
TPdfMergeNamedDestinationPolicy= (pndReject, pndRename, pndNamespace);
TPdfNavigationMergeOptions= record
NativeOptions: TPdfBatchMergeOptions;
NavigationPolicy: TPdfMergeNavigationPolicy;
MaxOutlineItems: Integer;
MaxOutlineDepth: Integer;
MaxTitleCharacters: Integer;
MaxDocumentBytes: Int64;
PreserveNamedDestinations, PreservePageLinks: Boolean;
NamedDestinationPolicy: TPdfMergeNamedDestinationPolicy;
DestinationPrefix: string;
MaxNamedDestinations, MaxPageLinks: Integer;
class function Default: TPdfNavigationMergeOptions; static;
end;
TPdfNavigationMergeReport= record
Succeeded: Boolean;
Cancelled: Boolean;
ImportedSourceCount: Integer;
ImportedPageCount: Integer;
PreservedOutlineCount: Integer;
RemovedDestinationCount: Integer;
SourceGroupCount: Integer;
PreservedNamedDestinationCount, RenamedNamedDestinationCount: Integer;
RemovedNamedDestinationCount, RemappedPageLinkCount, RemovedPageLinkCount: Integer;
ErrorMessage: string;
end;
// The caller's document is replaced only after the complete staged result
// has been independently reopened and its outline destinations checked
TPdfNavigationMergeHelper= class helper for TPdf
function MergeFilesWithNavigation(const Sources: TPdfBatchMergeSources;
const Options: TPdfNavigationMergeOptions;
out Report: TPdfNavigationMergeReport): Boolean;
end;
function MergePdfFilesWithNavigation(Destination: TPdf;
const Sources: TPdfBatchMergeSources;
const Options: TPdfNavigationMergeOptions;
out Report: TPdfNavigationMergeReport): Boolean;
FPdfCompress exposes CapturePdfNavigation and WritePdfNavigation for callers that manage their own page imports and sparse PDF revisions
TPdfNavigationNamedDestination.NameKey contains raw PDF key bytes; page numbers are absolute and one-based, while zero denotes an unresolved target
TPdfNavigationPageLink.PageNumber identifies the owner page; AnnotationIndex is the zero-based ordinal among all original annotations and LinkIndex is the zero-based ordinal among link annotations only
The writer identifies links by LinkIndex, clones each annotation with its final page owner and writes the supplied page targets and exact destination suffixes; callers must supply the complete mapping needed for their imports
The writer requires distinct source and output streams and an unencrypted, unsigned document; argument rejection with identical streams preserves the source, and other failures clear the separate output stream
These stream functions do not import pages or replace a live TPdf document; use the higher-level transactional function for complete navigation merging
function CapturePdfNavigation(Source: TStream; MaxNamedDestinations, MaxPageLinks, MaxDepth: Integer; out Names: TPdfNavigationNamedDestinations; out Links: TPdfNavigationPageLinks; out ErrorText: string): Boolean; function WritePdfNavigation(Source, Output: TStream; const Names: TPdfNavigationNamedDestinations; const Links: TPdfNavigationPageLinks; ReplaceNamedDestinations: Boolean; out ErrorText: string): Boolean;