PDFium Delphi Component Docs

ImportPagesByIndex 方法

元件: TPdf  ·  單元: PDFium
以零起始索引從另一個 TPdf 匯入特定的頁面子集,並可控制插入點在目前文件中的位置

語法

function ImportPagesByIndex(
  Source : TPdf;
  const PageIndices: array of Integer;
  InsertAt : Integer = 0): Boolean;

說明

ImportPagesByIndex 會從 Source 複製一組明確指定的頁面到 本文件。與解析以 1 為基底範圍字串("1-3,7,10-12")的 ImportPages 不同, ImportPagesByIndex 直接接受以 0 為基底的 Pascal 開放陣列作為索引 — 當頁面清單來自程式邏輯(勾選的縮圖清單、篩選後的查詢等)時最為理想

InsertAt 是第一個匯入頁面在目的端以 0 為基底的索引: 傳入 0 表示插入在現有第 1 頁之前,傳入 PageCount 則附加到 最後。超出範圍的 InsertAt 值會被 PDFium 限制在邊界內

傳入空的 PageIndices 陣列可匯入 Source 的全部頁面 (等同於在 C ABI 層級傳入 nil)。這是單次呼叫即可匯入全部頁面的簡寫

成功時傳回 True。若任一索引在 Source 中超出範圍, 或任一文件未處於 Active 狀態,則傳回 False。當 Source 為 nil 時會引發 EPdfError

備註

範例

var
  Source: TPdf;
begin
  Source := TPdf.Create(nil);
  try
    Source.FileName := 'C:\Report.pdf';
    Source.Active := True;
    // Import pages 1, 3, 5 (zero-based: 0, 2, 4) and append
    Pdf1.ImportPagesByIndex(Source, [0, 2, 4], Pdf1.PageCount);
    // Or import every source page at the start of Pdf1
    // Pdf1.ImportPagesByIndex(Source, [], 0);
  finally
    Source.Free;
  end;
end;

另請參閱

ImportPages, ImportNPagesToOne, MovePages