Display PDF from REST API Call.

195 views
Skip to first unread message

S R

unread,
Jan 20, 2017, 3:08:36 PM1/20/17
to PDFTron WebViewer
I am trying to use PDF Tron and I am able to display the pdf fine while loading it from local file system. I want the pdf to be displayed from data(blob) which comes from REST API. After annotating the pdf on save I want to post back pdf to the URL with annotations.
How do we do this ?

Justin Jung

unread,
Jan 23, 2017, 1:59:08 PM1/23/17
to pdfnet-w...@googlegroups.com
Hello Sandeep,

You can use document.getFileData function to retrieve the pdf data with annotations as the following:

function uploadPDF() {
  var docViewer = readerControl.docViewer;
  var doc = docViewer.getDocument();
  var annotManager = docViewer.getAnnotationManager();

  docViewer.getAnnotationsLoadedPromise().then(function() {
    var options = { 'xfdfString': annotManager.exportAnnotations(), 'flags': CoreControls.SaveOptions.LINEARIZED };
    doc.getFileData(options).then(function (data) {
      var arr = new Uint8Array(data);
      var blob = new Blob([arr], {
        type: 'application/pdf'
      });
      // post blob to the url
    });
  });
}


You could also refer to downloadFile function in PDFReaderControl.js.

Justin Jung
Software Developer
PDFTron Systems Inc.
Reply all
Reply to author
Forward
0 new messages