ExtractPageRanges

Document manipulation, Extraction, Page manipulation

Description

Use this function to extract one or more non-consecutive pages from a document to a new document

See Page selection syntax for strides, exclusions, open bounds and end-relative selectors

Syntax

Delphi

Function TPDFlib.ExtractPageRanges(Const RangeList: WideString): Integer;

ActiveX

Function PDFlib::ExtractPageRanges(RangeList As String) As Long

DLL

int DLExtractPageRanges(int InstanceID, const wchar_t* RangeList);
int DLExtractPageRangesA(int InstanceID, const char* RangeList);

Parameters

RangeListThe pages to extract, for example "10,15,18-20,25-35". Invalid characters and duplicate page numbers in the string will be ignored. Reversed page ranges such as "5-1" will be accepted. The list of pages will be sorted resulting in the pages being extracted in numerical order

Return values

0The page extraction did not succeed. The original document remains as the selected document
1The page extraction was successful. The new document containing the selected pages is now the selected document

Remarks

The pages are copied into a new document, which is then saved and reloaded; on success the reloaded document becomes the selected document, with a new document ID, while the original document stays open and unchanged. On failure LastErrorCode is set to 412 and the original document remains selected. Invalid characters and duplicate page numbers in RangeList are ignored and the pages are always extracted in ascending order; to keep a different order or repeat pages, use NewDocument with CopyPageRangesEx instead

The extraction follows the same copy path as CopyPageRanges. Optional content groups (layers) the extracted pages use are registered with their default state, so a layer that was off in the source stays off. A link, widget or bead that points at a page that was not extracted is given a null target. Named destinations that point at an extracted page come along, retargeted at the copy, and the extracted pages keep their page labels, continuing the source numbering. When the source is tagged, the structure elements with content on the extracted pages are copied into a new structure tree and the parent tree is rebuilt for them; elements whose content was not extracted are left out. Form fields whose widgets are on the extracted pages are carried over together with their default resources, and the document-level embedded files (/Names /EmbeddedFiles) and associated files (/AF) of the source are copied too