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, whilst the original document stays open and untouched. On failure LastErrorCode is set to 412 and the original document remains selected. Invalid characters and duplicate page numbers in RangeList are ignored, and pages are always extracted in ascending order; if you need a different order or repeated pages, use NewDocument with CopyPageRangesEx instead

Extraction goes through the same copy path as CopyPageRanges. Optional content groups (layers) used by the extracted pages are registered with their default state, so a layer that was switched off in the source stays off. A link, widget or bead pointing at a page that was not extracted is given a null target. Named destinations that point at an extracted page are carried across and retargeted at the copy, and the extracted pages keep their page labels, continuing the source numbering. If 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 dropped. Form fields with widgets on the extracted pages are brought over together with their default resources, and the source's document-level embedded files (/Names /EmbeddedFiles) and associated files (/AF) are copied as well