THotPDF Page Operation Methods

THotPDF

傳回頂部

這些方法提供 loaded-document workflow,用於插入、擷取、複製、儲存與重新排序頁面

 

Delphi 語法:

function HPDFParsePageRange(const PageRange: string; PageCount: Integer): THPDFPageIndexArray;

procedure AppendPagesFromDocument(SourceDoc: THotPDF; const PageRange: string);

procedure InsertPagesFromDocument(SourceDoc: THotPDF; const PageRange: string; InsertAfterPage: Integer);

procedure InsertPagesFromDocument(SourceDoc: THotPDF; const LogicalPageIndices: array of Integer; InsertAfterPage: Integer);

procedure CopyPageByPhysicalIndex(SourceDoc: THotPDF; SourceIndex: Integer; DestIndex: Integer);

procedure ExtractPagesToFile(const OutputFile: TFileName; const PageRange: string);

procedure ExtractPagesToFile(const OutputFile: TFileName; const LogicalPageIndices: array of Integer);

procedure MovePage(PageIndex: Integer; NewPageIndex: Integer);

procedure SaveLoadedDocument(const TargetFile: TFileName);

property OnPageOperationProgress: THPDFPageOperationProgressEvent;

 

說明

HPDFParsePageRange 會將從 1 起算的範圍字串(例如 1,3-4,6-)轉換為從 0 起算的頁面索引。輸入為空時選取所有頁面。頁碼無效、範圍遞減或語法錯誤的 token 會引發例外

InsertPagesFromDocument 會將另一個已載入 THotPDF instance 的頁面複製到目前檔案。既有 zero-based array calls 仍受支援,而 string overload 接受 one-based page ranges。InsertAfterPage 是 zero-based;傳入 -1 可插入到開頭

AppendPagesFromDocument 會使用相同的 one-based page-range syntax,將選取的來源頁面附加到目前檔案末尾

CopyPageByPhysicalIndex 依來源頁面從 0 起算的實體頁面索引複製單一頁面,並放到從 0 起算的目的位置

ExtractPagesToFile 會將目前檔案中選取的頁面寫入新的 PDF 檔案。既有 zero-based array calls 仍受支援,而 string overload 接受 one-based page ranges

OnPageOperationProgress 回報附加、插入、擷取,以及日後合併類頁面作業的頁面層級進度

MovePage 會將一個 zero-based page 移到另一個 zero-based position,以重新排序目前檔案。此方法會更新載入的 page array 與 root page tree,因此後續儲存與擷取呼叫會使用新的順序

SaveLoadedDocument 會在頁面編輯、表單編輯或複製作業之後,將已載入的物件圖形寫入新檔案

Code Example

BasePDF.LoadFromFile('base.pdf');
InsertPDF.LoadFromFile('insert.pdf');

BasePDF.InsertPagesFromDocument(InsertPDF, '1-2', 0);
BasePDF.AppendPagesFromDocument(InsertPDF, '2');
BasePDF.MovePage(BasePDF.PagesCount - 1, 1);
BasePDF.ExtractPagesToFile('selected-pages.pdf', '2,4');
BasePDF.SaveLoadedDocument('reordered.pdf');