PagesApi.extract()
Builds a new PDF from those pages, in that order. The source is untouched. A page with form fields comes out flattened, as it prints: its fields do not go to another document. The new document gets a creation date. Needs the
export feature.methodImport and extractsince 1.0.0
Signature
extract(indices: number[]): Promise<Uint8Array>
Parameters
| Parameter | Type | Description |
|---|---|---|
| indices | number[] | Zero-based page indices, in the order they should appear. |
Returns
Promise<Uint8Array> The new PDF's bytes.
Throws
INVALID_ARGUMENT— no pages, or a page the document lacks.PAGE_ERROR— the pages could not be copied.EXPORT_FAILED— a page with form fields could not be flattened, or the new document could not be watermarked or serialized.FEATURE_NOT_LICENSED— the license lacksexport.DOCUMENT_CLOSED— the document has been closed.INVALID_STATE— a progressive document still downloading.
Example
TypeScript
const firstTwo = await doc.pages.extract([0, 1]);