Some test text!

Inserting pages

Pages can be inserted into the current PDF document using the insertBlankPages and insertPages functions. Inserting blank pages is fairly straight forward.

viewerElement.addEventListener('documentLoaded', function() {   
  var docViewer = myWebViewer.getInstance().docViewer;
  var doc = docViewer.getDocument();

  var width = 612;
  var height = 792;
  docViewer.getPageCount(); // 3

  // Insert blank pages
  doc.insertBlankPages([2, 3], width, height).then(function(pagesArray) {
    // The document now contains [page1, newBlankPage1, page2, newBlankPage2, page3]
    docViewer.getPageCount(); // 5
  });
});

More likely someone will want to insert pages from one PDF into another. To achieve this, instantiate a new Document object and load data into it using the loadAsync function. In the example below, the loadAsync function takes in an ExternalPdfPartRetriever object to load a PDF from an external URL but any PartRetriever can be used to load data.

Currently there aren't any functions to duplicate pages in the current document. If someone wanted to copy a page, instantiate a new Document object and load the current PDF data into it using a PartRetriever and insert the page into the current document.
viewerElement.addEventListener('documentLoaded', function() {   
  var docViewer = myWebViewer.getInstance().docViewer;
  var doc = docViewer.getDocument();
  var documentID = 'another.pdf';
  // documentID can be anything but should be unique
  var documentType = 'pdf';
  var CoreControls =  viewerElement.querySelector('iframe').contentWindow.CoreControls;

  var licenseKey = 'YOUR_LICENSE_KEY_HERE';
  var workerHandlers = {};

  var docToInsert = new CoreControls.Document(documentID, documentType);
  CoreControls.getDefaultBackendType()
  .then(function(backendType) {
    var workerTransportPromise = CoreControls.initPDFWorkerTransports(backendType, workerHandlers, licenseKey);
    var options = { workerTransportPromise: workerTransportPromise };

    // any 'partRetrievers' can be used here
    var partRetriever = new CoreControls.PartRetrievers.ExternalPdfPartRetriever(
      'http://localhost/pdf/another.pdf'
    );

    docToInsert.loadAsync(partRetriever, function(err) {
      var pagesToInsert = [4, 5, 6];
      var pageIndexToInsert = doc.getPageCount() + 1;
      // in this example doc.getPageCount() returns 3

      doc.insertPages(docToInsert, pagesToInsert, pageIndexToInsert)
      .then(function() {
        // page 4, 5, and 6 from 'another.pdf' has been inserted into to the current pdf
        doc.getPageCount(); // 6
      });
    }, options);
  });
});

Get the answers you need: Support