Section:

Extracting pages from PDF using JavaScript

If the user only wants to download part of a document, the extractPages function can be used to download specific pages. For example:

1// config.js
2const { documentViewer, annotationManager } = instance.Core;
3
4documentViewer.addEventListener('documentLoaded', async () => {
5 const doc = documentViewer.getDocument();
6 const pagesToExtract = [2, 3];
7
8 // only include annotations on the pages to extract
9 const annotList = annotationManager.getAnnotationsList().filter(annot => pagesToExtract.indexOf(annot.PageNumber) > -1);
10 const xfdfString = await annotationManager.exportAnnotations({ annotList });
11 const data = await doc.extractPages(pagesToExtract, xfdfString);
12 const arr = new Uint8Array(data);
13
14 //optionally save the blob to a file or upload to a server
15 const blob = new Blob([arr], { type: 'application/pdf' });
16});

Did you find this helpful?

Trial setup questions?

Ask experts on Discord

Need other help?

Contact Support

Pricing or product questions?

Contact Sales