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:

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

Did you find this helpful?

Trial setup questions?

Ask experts on Discord

Need other help?

Contact Support

Pricing or product questions?

Contact Sales