function ImportPagesByIndex(
Source : TPdf;
const PageIndices: array of Integer;
InsertAt : Integer = 0): Boolean;
ImportPagesByIndex 會將 Source 中明確指定的一組頁面複製到本文件。不同於會解析一基底範圍字串
("1-3,7,10-12") 的 ImportPages,ImportPagesByIndex 會直接把索引當作零起始的 Pascal 開放陣列傳入 — 當頁面清單來自程式邏輯時特別適合,例如核取過的縮圖清單或過濾後的查詢結果
InsertAt 是第一個匯入頁面的零起始目的地索引:傳入 0 會插入到現有第 1 頁之前,傳入 PageCount 則會附加到末尾。超出範圍的 InsertAt 值會由 PDFium 夾限
傳入空白的 PageIndices 陣列即可匯入 Source 的每一頁(相當於在 C ABI 層級傳入 nil)。這就是一次呼叫匯入全部的簡寫方式
成功時傳回 True。若 Source 中任何索引超出範圍,或任一文件不是 Active,則傳回 False。當 Source 為 nil 時會拋出 EPdfError
MovePages 在原處重新排序PageIndices 中的索引會依據 Source 的目前狀態計算;在呼叫之後對 Source 進行重新排序或刪除,不會反過來改變已匯入的內容ImportNPagesToOne
var
Source: TPdf;
begin
Source := TPdf.Create(nil);
try
Source.FileName := 'C:\Report.pdf';
Source.Active := True;
// 匯入第 1、3、5 頁(零起始為 0、2、4)並附加到末尾
Pdf1.ImportPagesByIndex(Source, [0, 2, 4], Pdf1.PageCount);
// 或在 Pdf1 開頭匯入每一個來源頁面
// Pdf1.ImportPagesByIndex(Source, [], 0);
finally
Source.Free;
end;
end;