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 是 TPdfBatchMergeSource 記錄的動態陣列,也是兩個 MergeFiles 多載都接受的來源清單;來源按陣列順序開啟並匯入,清單可以用 SetLength 搭配 TPdfBatchMergeSource.FromFile 直接以行內方式建立
FileName 識別單一檔案式 PDF 來源Password 會在來源開啟前套用PageRange 是以逗號分隔、以 1 為基底的清單,例如 1,3,5-7PageRange 會匯入所有頁面| ErrorPolicy | bmepStop |
| FormPolicy | bmfpPreserveNative |
| OutlinePolicy | bmopDiscard |
| ResourcePolicy | bmrpSourceScoped |
| PageChunkSize | PdfBatchMergeDefaultPageChunkSize,目前為 128 頁 |
| InsertAt | -1,附加至目的地 |
| CreateDestination | True |
| CopyViewerPreferences | True |
| RollbackOnCancelOrFailure | True |
bmrpSourceScoped 對每個來源執行一次原生匯入,讓 PDFium 可對該來源的所有選定頁面重複使用其複製的物件映射
bmrpChunked 將選取範圍切成大小為 PageChunkSize 的區塊,以更細的取消點與更小的原生呼叫為代價,可能產生跨區塊的資源重複
一次最多開啟一個來源 TPdf,且每個來源在匯入嘗試後立即關閉
取消會在來源作業與原生批次之間檢查;單一 PDFium 匯入呼叫無法被中斷
OnProgress 會收到 started、opening、importing、source、rollback、cancellation、failure 與 completion 階段,並可設定其 Cancel 參數;每份 TPdfBatchMergeProgress 快照都攜帶 Stage、SourceIndex、SourceCount、FileName、SourcePageCount、ImportedSourceCount、ImportedPageCount 與 NativeImportCallCount
TPdfBatchMergeReport 會傳回 Status、SourceCount、AttemptedSourceCount、ImportedSourceCount、SkippedSourceCount、FailedSourceCount、ImportedPageCount、CommittedPageCount、RolledBackPageCount、PageCountBefore、PageCountAfter、NativeImportCallCount、LargestNativeImportPageCount、PeakOpenSourceCount、FormSourceCount、OutlineSourceCount、DestinationCreated、ViewerPreferencesSourceIndex、ErrorMessage 與 Issues
CancellationToken 接受與非同步及漸進 API 所使用之相同的 IPdfCancellationToken 合約
bmfpPreserveNative 保留 PDFium 盡力而為的頁面與 widget 匯入,但不會解決 AcroForm 欄位樹、同名欄位、資源、預設外觀或計算順序的衝突bmfpFlatten 產生外觀並在匯入前僅攤平選定的來源頁面bmfpReject 拒絕 AcroForm 與 XFA 來源bmopDiscard 匯入頁面而不重建來源大綱,bmopReject 則拒絕含有大綱的來源CopyViewerPreferences 時,檢視器偏好會在第一個成功來源的頁面成功匯入後盡力複製;當該來源沒有受支援的項目時,ViewerPreferencesSourceIndex 保持 -1某個來源在一或多個區塊已插入頁面後才失敗時,一律會先回滾到該來源邊界,再進行停止或跳過處理
bmepSkip 記錄問題並繼續下一個來源,bmepStop 則終止作業
在 RollbackOnCancelOrFailure=True 時,停止失敗與取消會移除作業插入的所有頁面;由作業建立的目的地會被關閉
停用回滾時,成功匯入的來源保持已認可狀態,並反映在 CommittedPageCount 中
回滾會移除插入的頁面,但無法保證反轉每個原生的目錄副作用,例如 producer 中繼資料
Status 為 bmrsCompleted、bmrsCompletedWithErrors、bmrsCancelled 或 bmrsFailed
報告會區分嘗試、匯入、跳過與失敗的來源,以及匯入、已認可與已回滾的頁面
NativeImportCallCount、LargestNativeImportPageCount 與 PeakOpenSourceCount 讓所選的排程政策可被量測
Issues 會保留失敗與非致命終端回呼錯誤的來源索引、檔名與錯誤文字
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 提供相同的頁面區間解析器供輔助流程使用;交易式大綱保留請參閱 FPdfMerge
需要明確的 AcroForm 名稱衝突策略與獨立可編輯值時,請使用 MergePdfFilesWithForms;原生 MergeFiles 保留既有表單匯入行為