Include FPdfFormMerge to use either MergePdfFilesWithForms or TPdfFormMergeHelper.MergeFilesWithForms
The helper stages imports of selected pages and field grafting, discards orphaned imported widgets, and independently reopens the saved output before replacing the caller's document; errors or cancellation leave the destination intact
Duplicate fully qualified field names are refused by pagcpReject; pagcpRename supplies deterministic, collision-free prefixes and suffixes, whilst pagcpNamespace isolates each source beneath an actual parent field
With pagcpMergeCompatible, compatible terminal text or choice fields are joined so that their widgets share a value; flags, values, defaults, options and self-contained font semantics must agree, and field actions, rich text or incompatible types are refused
Page selection prunes unused widgets and fields and retains a filtered, deduplicated calculation order; default resources are isolated and default-appearance names rewritten, but cloned appearance streams keep their own resources
Combined field/widget objects are normalised before compatible fields are joined; separately named fields can still be edited independently after saving and reopening
InsertAt counts from zero, with -1 meaning append; Default allows 10,000 pages overall and 256 MiB per document, and grafting permits 100,000 objects to depth 128
Grafting has hard limits of 1,000,000 objects, depth 256 and 4,096 root fields; repeated selected pages, XFA input or output, signed input or output, and encrypted destinations are refused
A source password can decrypt input for the staged merge; output is unencrypted, so explicitly encrypt it afterwards if required
The original GraftPdfAcroForm overload continues to reject collisions; the overload taking TPdfAcroFormGraftOptions makes the same collision and resource policies available for streams
Source outlines and named destinations are outside this form helper's remit; use the navigation helper for the navigation workflow it documents
Options := TPdfFormMergeOptions.Default; Options.GraftOptions.CollisionPolicy := pagcpNamespace; if not MergePdfFilesWithForms(Pdf, Sources, Options, Report) then raise EPdfError.Create(Report.ErrorMessage);
type
TPdfFormMergeOptions= record
GraftOptions: TPdfAcroFormGraftOptions;
InsertAt: Integer;
MaxPages: Integer;
MaxDocumentBytes: Int64;
CancellationToken: IPdfCancellationToken;
class function Default: TPdfFormMergeOptions; static;
end;
TPdfFormMergeReport= record
Succeeded, Cancelled: Boolean;
ImportedSourceCount, ImportedPageCount: Integer;
GraftedFieldCount, RenamedFieldCount, MergedFieldCount: Integer;
FilteredFieldCount, FilteredWidgetCount, ResourceRenameCount: Integer;
ErrorMessage: string;
end;
function MergePdfFilesWithForms(Destination: TPdf;
const Sources: TPdfBatchMergeSources; const Options: TPdfFormMergeOptions;
out Report: TPdfFormMergeReport): Boolean;
type
TPdfFormMergeHelper= class helper for TPdf
function MergeFilesWithForms(const Sources: TPdfBatchMergeSources;
const Options: TPdfFormMergeOptions;
out Report: TPdfFormMergeReport): Boolean;
end;