PDFium Delphi Component Docs

MovePages 方法

组件: TPdf  ·  单元: PDFium
按零基索引就地重新排序本文档页面,同时保持页数不变

语法

function MovePages(
  const PageIndices: array of Integer;
  DestPageIndex : Integer): Boolean;

说明

MovePages 重新排序本文档的页面。PageIndices 列出要移动页面的基于 0 的索引(任何顺序,任何 数量,最多 PageCount 个);DestPageIndex 是 移动完成后第一个被移动页面的目标索引。 其他页面围绕被移动块移动,因此文档 长度保持不变

示例:在页面编号为 [0, 1, 2, 3, 4] 的 5 页文档中, MovePages([2, 3], 0) 产生 [2, 3, 0, 1, 4] — 第 2 和第 3 页被移出, 第 0 页移到位置 2(第 2 页原来的位置),第 1 页移到 位置 3,第 4 页保持原位

成功时返回 True。如果 PageIndices 中任何索引超出范围、 DestPageIndex 超出范围,或 PageIndices 包含重复项,则返回 False

这是 UI 中“上移 / 下移所选缩略图” / 拖放页面重新排序的正确调用。要从另一个文档复制页面子集, 使用 ImportPagesByIndex;要 删除页面,使用 DeletePage

备注

示例

// 在 5 页文档中,将第 2 和第 3 页移到开头
// 结果:[2, 3, 0, 1, 4]
if not Pdf1.MovePages([2, 3], 0) then
  ShowMessage('Invalid indices passed to MovePages');

// 反转整个文档
var
  I: Integer;
  Indices: array of Integer;
begin
  SetLength(Indices, Pdf1.PageCount);
  for I := 0 to High(Indices) do
    Indices[I] := High(Indices) - I;
  Pdf1.MovePages(Indices, 0);
end;

参见

ImportPagesByIndex, ImportNPagesToOne, DeletePage, AddPage