function ImportPagesByIndex(
Source : TPdf;
const PageIndices: array of Integer;
InsertAt : Integer = 0): Boolean;
ImportPagesByIndex copies an explicit set of pages from
Source into THIS document. Unlike
ImportPages, which parses a one-based range string
("1-3,7,10-12"), ImportPagesByIndex takes the indices directly as a
zero-based Pascal open array — ideal when the page list comes
from program logic (a checked list of thumbnails, a filtered query,
etc.)
InsertAt is the zero-based destination index for the
FIRST imported page: pass 0 to insert before the existing page 1,
pass PageCount to append. Out-of-range
InsertAt values are clamped by PDFium
Pass an empty PageIndices array to import every page
from Source (equivalent to passing
nil at the C ABI level). This is the
one-call-imports-everything shorthand
Returns True on success. Returns False
if any index is out of range in Source or if either
document is not Active. Raises EPdfError
when Source is nil
MovePages to reorder in placePageIndices are evaluated against Source's current state; reorders or deletions in Source after the call do not retroactively change what was importedImportNPagesToOne instead when the goal is to compose pages onto a new document (N-up grid) rather than to copy them
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;