|
| 1 | +--- |
| 2 | +layout: post |
| 3 | +title: Extract Pages in TypeScript PDF Viewer | Syncfusion |
| 4 | +description: Learn here all about Extract Pages in Organize Pages in Syncfusion TypeScript PDF Viewer control of Syncfusion Essential JS 2 and more. |
| 5 | +platform: document-processing |
| 6 | +control: PDF Viewer |
| 7 | +documentation: ug |
| 8 | +domainurl: ##DomainURL## |
| 9 | +--- |
| 10 | + |
| 11 | +# Extract pages in TypeScript PDF Viewer |
| 12 | + |
| 13 | +The PDF Viewer component lets you extract pages from a document using the Extract Pages option in the Organize Pages UI, and also control extraction programmatically. |
| 14 | +The Extract Pages tool is available by default in Organize Pages. |
| 15 | + |
| 16 | +## Extract Pages in Organize Pages |
| 17 | + |
| 18 | +- Open the Organize Pages panel in the PDF Viewer toolbar. |
| 19 | +- Locate and click the Extract Pages option. |
| 20 | + |
| 21 | + |
| 22 | + |
| 23 | +When selected, a secondary toolbar dedicated to extraction is displayed. |
| 24 | + |
| 25 | + |
| 26 | + |
| 27 | +## Extract pages using the UI |
| 28 | + |
| 29 | +You can extract by typing page numbers/ranges or by selecting thumbnails. |
| 30 | + |
| 31 | +1. Click Extract Pages in the Organize Pages panel. |
| 32 | +2. In the input box, enter the pages to extract. Supported formats include: |
| 33 | + - Single pages: 1,3,5 |
| 34 | + - Ranges: 2-6 |
| 35 | + - Combinations: 1,4,7-9 |
| 36 | +3. Alternatively, select the page thumbnails you want instead of typing values. |
| 37 | +4. Click Extract to download the extracted pages as a new PDF. Click Cancel to close the tool. |
| 38 | + |
| 39 | + |
| 40 | + |
| 41 | + N> Page numbers are 1-based (first page is 1). You can start anywhere—enter single pages or ranges like 2-3, 5, or 7-9. Invalid or out-of-range entries are ignored. |
| 42 | + |
| 43 | +## Extraction options (checkboxes) |
| 44 | + |
| 45 | +Two options appear in the secondary toolbar: |
| 46 | + |
| 47 | +- **Delete Pages After Extracting:** |
| 48 | + - When enabled, the selected/entered pages are removed from the document opened in the viewer after the extraction completes. The extracted pages are still downloaded as a new file. |
| 49 | + - Example: If you enter 1,2 and extract, a PDF containing pages 1 and 2 is downloaded, and pages 1 and 2 are removed from the currently loaded document in the viewer. |
| 50 | + |
| 51 | +- **Extract Pages As Separate Files:** |
| 52 | + - When enabled, every selected page is exported as an individual PDF file. |
| 53 | + - Example: If you select pages 3, 5, and 6, three separate PDFs are downloaded (3.pdf, 5.pdf, and 6.pdf). If you enter a range (e.g., 2-4), pages 2, 3, and 4 are each downloaded as separate PDFs. |
| 54 | + |
| 55 | + |
| 56 | + |
| 57 | +## Programmatic options and APIs |
| 58 | + |
| 59 | +You can control the Extract Pages experience via settings and invoke extraction through code. |
| 60 | + |
| 61 | +### Enable/disable Extract Pages |
| 62 | + |
| 63 | +Use the `canExtractPages` API to enable or disable the Extract Pages option. When set to `false`, the Extract Pages tool is disabled in the toolbar. The default value is `true`. |
| 64 | + |
| 65 | +Use the following code snippet to enable or disable the Extract Pages option: |
| 66 | + |
| 67 | +```ts |
| 68 | +// Enable the Extract Pages Tool |
| 69 | +viewer.pageOrganizerSettings = { canExtractPages: true }; |
| 70 | +``` |
| 71 | + |
| 72 | +```ts |
| 73 | +// Disable the Extract Pages Tool |
| 74 | +viewer.pageOrganizerSettings = { canExtractPages: false }; |
| 75 | +``` |
| 76 | + |
| 77 | +Use the `showExtractPagesOption` API to show or hide the Extract Pages option. When set to `false`, the Extract Pages tool is removed from the toolbar. The default value is `true`. |
| 78 | + |
| 79 | +Use the following code snippet to remove the Extract Pages option: |
| 80 | +```ts |
| 81 | +// Remove the Extract Pages option entirely from the UI (redacted example as provided) |
| 82 | +viewer.pageOrganizerSettings = { showExtractPagesOption: false } |
| 83 | +``` |
| 84 | + |
| 85 | +### Extract pages and load the result programmatically |
| 86 | + |
| 87 | +You can extract pages programmatically using the `extractPages` method. |
| 88 | +The following example extracts pages 1 and 2, then immediately loads the extracted pages back into the viewer. The returned value is a byte array (e.g., Uint8Array) representing the PDF file contents. |
| 89 | + |
| 90 | +```html |
| 91 | +<button id="extractPage">Extract Pages</button> |
| 92 | +``` |
| 93 | + |
| 94 | +```ts |
| 95 | +document.getElementById('extractPage').addEventListener('click', function () { |
| 96 | + // Extract pages 1 and 2 |
| 97 | + var array = viewer.extractPages("1,2"); |
| 98 | + |
| 99 | + // Load the extracted pages back into the viewer |
| 100 | + viewer.load(array); |
| 101 | + |
| 102 | + // Inspect the result if needed |
| 103 | + console.log(array); |
| 104 | +}); |
| 105 | +``` |
| 106 | + |
| 107 | +[View sample in GitHub](https://github.com/SyncfusionExamples/typescript-pdf-viewer-examples/tree/master/How%20to) |
| 108 | + |
| 109 | +## See also |
| 110 | + |
| 111 | +- [Overview](../overview) |
| 112 | +- [UI interactions](../ui-interactions) |
| 113 | +- [Programmatic support](../programmatic-support) |
| 114 | +- [Toolbar](../toolbar) |
| 115 | +- [Events](../events) |
| 116 | +- [Mobile view](../mobile-view) |
0 commit comments