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;
    // 导入第 1、3、5 页(基于 0:0、2、4)并追加
    Pdf1.ImportPagesByIndex(Source, [0, 2, 4], Pdf1.PageCount);
    // 或在 Pdf1 开头导入每个源页面
    // Pdf1.ImportPagesByIndex(Source, [], 0);
  finally
    Source.Free;
  end;
end;

参见

ImportPages, ImportNPagesToOne, MovePages