ReplacePageRanges

Document manipulation

Description

Replaces the visual content and page-level presentation of existing pages in the selected document with pages imported from another open document while retaining the target page objects

Syntax

Delphi

Function TPDFlib.ReplacePageRanges(DocumentID, TargetStartPage: Integer; Const RangeList: WideString; Options: Integer= 0): Integer;

Parameters

DocumentIDThe identifier of the open source document, which must differ from the selected target document
TargetStartPageThe 1-based page number in the selected target document where replacement begins
RangeListThe source-page range expression, for example "1-3,5"; invalid characters or out-of-range pages make the entire call fail
Options0 sorts pages and removes duplicates; 1 preserves source order and permits repeated page numbers

Return values

0Validation or replacement failed and the target pages were left unchanged
1The requested target pages were replaced

Remarks

The operation transfers Contents, Resources, the five page boxes, Rotate, Group, UserUnit, and BoxColorInfo. Target page object numbers, annotations, form widgets, bookmark destinations, and other existing references remain attached. Source annotations, form fields, and outlines are not imported. The page count stays unchanged, and all source ranges plus target capacity are validated before modification

Example

var SourceDoc: Integer;
SourceDoc := PDF.LoadFromFile('source.pdf', '');
PDF.SelectDocument(MainDoc);
// Replace page 2 of MainDoc with page 1 of source.pdf
PDF.ReplacePageRanges(SourceDoc, 2, '1', 0);

See also

CopyPageRanges, DeletePages, InsertPages