PDFiumPas 文档

MovePages 方法

此 API 条目保留标识符、签名、代码块和 PDF 术语的原始形式。
组件: TPdf  ·  单元: PDFium
按零基索引就地重新排序本文档页面,同时保持页数不变

语法

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

说明

MovePages reorders pages of THIS document. PageIndices lists the zero-based indices of the pages to move (any order, any count up to PageCount); DestPageIndex is the destination index for the FIRST moved page after the move completes. Other pages shift around the moved block so the document length stays the same.

Example: in a 5-page document with pages numbered [0, 1, 2, 3, 4], MovePages([2, 3], 0) produces [2, 3, 0, 1, 4] — pages 2 and 3 are lifted out, page 0 shifts to position 2 (where page 2 was), page 1 shifts to position 3, and page 4 stays put.

Returns True on success. Returns False if any index in PageIndices is out of range, if DestPageIndex is out of range, or if PageIndices contains duplicates.

This is the right call for "move selected thumbnails up / down" / drag-and-drop page reordering in a UI. To copy a subset of pages from another document, use ImportPagesByIndex; to delete pages, use 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