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

備註

範例

// In a 5-page document, move pages 2 and 3 to the start
// Result: [2, 3, 0, 1, 4]
if not Pdf1.MovePages([2, 3], 0) then
  ShowMessage('Invalid indices passed to MovePages');

// Reverse the entire document
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