Some test text!

Loading...
Guides
Extract pages

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:

// config.js
const { documentViewer, annotationManager } = instance.Core;

documentViewer.addEventListener('documentLoaded', async () => {
  const doc = documentViewer.getDocument();
  const pagesToExtract = [2, 3];

  // only include annotations on the pages to extract
  const annotList = annotationManager.getAnnotationsList().filter(annot => pagesToExtract.indexOf(annot.PageNumber) > -1);
  const xfdfString = await annotationManager.exportAnnotations({ annotList });
  const data = await doc.extractPages(pagesToExtract, xfdfString);
  const arr = new Uint8Array(data);

  //optionally save the blob to a file or upload to a server
  const blob = new Blob([arr], { type: 'application/pdf' });
});

Get the answers you need: Support

Upcoming Webinar: PDFTron SDK Tech Review | Nov 29, 2022 at 2 pm ET

PDFTron SDK

The Platform

NEW

© 2022 PDFTron Systems Inc. All rights reserved.

Privacy

Terms of Use