2

I have a PDFTron webviewer which I use to render a pdf form. I need to extract the form xml from the webviewer when user click on external save button.

I tried

var am = readerControl.docViewer.getAnnotationManager();
var xfdfString = am.exportAnnotations();

$.ajax({
       type: 'POST',
       url: readerControl.serverUrl + '?did=' + readerControl.docId,
       data: xfdfString,
       success: function(data) {
         // Annotations were successfully uploaded to server
       },
       error: function(jqXHR, textStatus, errorThrown) {
         console.warn("Failed to send annotations to server. " + textStatus);
       },
       dataType: 'xml'
   });

But I cannot get hold of readerControl outside the PDFTron config.js. Please help

gmuraleekrishna
  • 3,375
  • 1
  • 27
  • 45

1 Answers1

3

config.js is the preferred place for webviewer modifications because it executes in the context of the viewer's iframe window. More on this in the following tutorial:

https://www.pdftron.com/webviewer/demo/tutorials/getting-started-config-files.html

Alternatively you could access iframe variables through contentWindow as described in the following post: https://stackoverflow.com/a/13758233/1710586

Community
  • 1
  • 1
Anatoly
  • 125
  • 7
  • How can I get the file data as I have inside the viewer (`documentViewer.getDocument().getFileData()`) by the `contentWindow`? – ESI May 15 '23 at 08:58