MCPcopy Create free account
hub / github.com/LibPDF-js/core / extractPages

Method extractPages

src/api/pdf.ts:1816–1835  ·  view source on GitHub ↗

* Extract pages into a new PDF document. * * Creates a new document containing only the specified pages, copied from * this document. The original document is not modified. * * @param indices - Array of page indices to extract (0-based) * @param options - Extraction options * @r

(indices: number[], options: ExtractPagesOptions = {})

Source from the content-addressed store, hash-verified

1814 * ```
1815 */
1816 async extractPages(indices: number[], options: ExtractPagesOptions = {}): Promise<PDF> {
1817 // Validate indices first
1818 for (const index of indices) {
1819 if (index < 0 || index >= this.getPageCount()) {
1820 throw new RangeError(`Page index ${index} out of bounds (0-${this.getPageCount() - 1})`);
1821 }
1822 }
1823
1824 // Create new empty document
1825 const result = PDF.create();
1826
1827 // Copy pages from this document to the new one
1828 if (indices.length > 0) {
1829 await result.copyPagesFrom(this, indices, {
1830 includeAnnotations: options.includeAnnotations ?? true,
1831 });
1832 }
1833
1834 return result;
1835 }
1836
1837 /**
1838 * Embed a page from another PDF as a reusable Form XObject.

Callers 6

pdf.test.tsFile · 0.80
mainFunction · 0.80
mainFunction · 0.80
mainFunction · 0.80
splitting.bench.tsFile · 0.80

Calls 3

getPageCountMethod · 0.95
copyPagesFromMethod · 0.80
createMethod · 0.65

Tested by

no test coverage detected