* 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 = {})
| 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. |
no test coverage detected