Some test text!

menu
search
Split pageskeyboard_arrow_down

Extracting pages from PDF

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

WebViewer(...)
  .then(function(instance) {
    var docViewer = instance.docViewer;
    var annotManager = instance.annotManager;

    docViewer.on('documentLoaded', function() {
      var doc = docViewer.getDocument();
      var pagesToExtract = [2, 3];

      // only include annotations on the pages to extract
      var annotList = annotManager.getAnnotationsList().filter(function(annot) {
        return pagesToExtract.indexOf(annot.PageNumber) > -1;
      });
      var xfdfString = annotManager.exportAnnotations({ annotList: annotList });

      doc.extractPages(pagesToExtract, xfdfString).then(function(data) {
        var arr = new Uint8Array(data);
        var blob = new Blob([arr], { type: 'application/pdf' });

        // in this example we are using FileSaver.js library  'SaveAs' function but any technique to save a blob works
        saveAs(blob, 'downloaded.pdf');
      });
    });
  });

Get the answers you need: Support

close

Free Trial

Get unlimited trial usage of PDFTron SDK to bring accurate, reliable, and fast document processing capabilities to any application or workflow.

Select a platform to get started with your free trial.

Unlimited usage. No email address required.

PDFTron Receives USD$71 Million Growth Investment Led By Silversmith Capital Partners

Learn more
close