function MergeFiles(const Sources: TPdfBatchMergeSources; out Report: TPdfBatchMergeReport): Boolean; overload;
function MergeFiles(const Sources: TPdfBatchMergeSources; const Options: TPdfBatchMergeOptions; out Report: TPdfBatchMergeReport): Boolean; overload;
class function TPdfBatchMergeSource.FromFile(const AFileName: string; const APageRange: string = ''; const APassword: string = ''): TPdfBatchMergeSource; static;
class function TPdfBatchMergeOptions.Default: TPdfBatchMergeOptions; static;
TPdfBatchMergeSources is a dynamic array of TPdfBatchMergeSource records and is the source list both MergeFiles overloads accept; sources are opened and imported in array order, and the list can be built inline with SetLength and TPdfBatchMergeSource.FromFile
FileName identifies one file-backed PDF sourcePassword is applied before the source is openedPageRange is a comma-separated 1-based list such as 1,3,5-7PageRange imports all pages| ErrorPolicy | bmepStop |
| FormPolicy | bmfpPreserveNative |
| OutlinePolicy | bmopDiscard |
| ResourcePolicy | bmrpSourceScoped |
| PageChunkSize | PdfBatchMergeDefaultPageChunkSize, currently 128 pages |
| InsertAt | -1, which appends to the destination |
| CreateDestination | True |
| CopyViewerPreferences | True |
| RollbackOnCancelOrFailure | True |
bmrpSourceScoped performs one native import per source, allowing PDFium to reuse its cloned-object map across all selected pages from that source
bmrpChunked splits the selection into batches of PageChunkSize, providing finer cancellation points and smaller native calls at the cost of possible cross-chunk resource duplication
At most one source TPdf is open at a time and every source is closed immediately after its import attempt
Cancellation is checked between source operations and native batches; an individual PDFium import call cannot be interrupted
OnProgress receives started, opening, importing, source, rollback, cancellation, failure, and completion stages and can set its Cancel parameter; each TPdfBatchMergeProgress snapshot carries Stage, SourceIndex, SourceCount, FileName, SourcePageCount, ImportedSourceCount, ImportedPageCount, and NativeImportCallCount
The TPdfBatchMergeReport returns Status, SourceCount, AttemptedSourceCount, ImportedSourceCount, SkippedSourceCount, FailedSourceCount, ImportedPageCount, CommittedPageCount, RolledBackPageCount, PageCountBefore, PageCountAfter, NativeImportCallCount, LargestNativeImportPageCount, PeakOpenSourceCount, FormSourceCount, OutlineSourceCount, DestinationCreated, ViewerPreferencesSourceIndex, ErrorMessage, and Issues
CancellationToken accepts the same IPdfCancellationToken contract used by the asynchronous and progressive APIs
bmfpPreserveNative keeps PDFium's best-effort page and widget import but does not resolve AcroForm field-tree, same-name field, resource, default appearance, or calculation-order conflictsbmfpFlatten generates appearances and flattens only selected source pages before importbmfpReject rejects AcroForm and XFA sourcesbmopDiscard imports pages without rebuilding the source outline, while bmopReject rejects sources that contain an outlineCopyViewerPreferences is enabled; ViewerPreferencesSourceIndex remains -1 when that source has no supported entriesA source that fails after one or more chunks has inserted pages is always rolled back to its source boundary before stop or skip handling
bmepSkip records the issue and continues with the next source, while bmepStop terminates the operation
With RollbackOnCancelOrFailure=True, stop failures and cancellation remove all pages inserted by the operation; a destination created by the operation is closed
With rollback disabled, successfully imported sources remain committed and are reflected in CommittedPageCount
Rollback removes inserted pages but cannot guarantee reversal of every native catalog side effect such as producer metadata
Status is bmrsCompleted, bmrsCompletedWithErrors, bmrsCancelled, or bmrsFailed
The report separates attempted, imported, skipped, and failed sources from imported, committed, and rolled-back pages
NativeImportCallCount, LargestNativeImportPageCount, and PeakOpenSourceCount make the chosen scheduling policy measurable
Issues retains source index, file name, and error text for failures and non-fatal terminal callback errors
var
Sources: TPdfBatchMergeSources;
Options: TPdfBatchMergeOptions;
Report: TPdfBatchMergeReport;
begin
SetLength(Sources, 2);
Sources[0] := TPdfBatchMergeSource.FromFile('part-a.pdf', '1-10');
Sources[1] := TPdfBatchMergeSource.FromFile('part-b.pdf', '3,1', Password);
Options := TPdfBatchMergeOptions.Default;
Options.ErrorPolicy := bmepSkip;
Options.FormPolicy := bmfpFlatten;
if not Pdf.MergeFiles(Sources, Options, Report) then
Log(Report.ErrorMessage);
end;
ParsePdfBatchMergePageRange exposes the same page-range parser for helper workflows; for transactional outline preservation see FPdfMerge
Use MergePdfFilesWithForms for explicit AcroForm name-collision policies and independent editable values; native MergeFiles retains its existing form import behavior