PDFiumPas 文档

ImportPagesByIndex 方法

此 API 条目保留标识符、签名、代码块和 PDF 术语的原始形式。
组件: TPdf  ·  单元: PDFium
按零基索引从另一个 TPdf 导入指定的一组页面,并控制它们在当前文档中的插入位置

语法

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。当 Sourcenil 时会引发 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