1

I have created a Dynamic XFA form using Livecycle designer.I'm using pdf.js to get the form fields.But after enabling "enable usage rights" to the form it shows the form field length is 0. I'm using page.getAnnotations() of pdf.js to get it.

user_new
  • 21
  • 6

2 Answers2

1

If the form is static XFA, the PDF contains an AcroForm dictionary in addition to the XFA dictionary which is how non-Adobe viewers can handle static XFA. They don't handle the XFA, they read the AcroForm as though the XFA didn't exist. However, with Dynamic XFA, it is very likely that there are no form fields in the AcroForm dictionary until the viewer renders the XFA into a PDF... Acrobat does this automatically but other libraries that can't create a PDF DOM from the XFA DOM won't be able to. I doubt your issue has anything to do with usage rights other than the fact that saving the file caused Acrobat to wipe the PDF counterpart to the XFA.

joelgeraci
  • 4,606
  • 1
  • 12
  • 19
  • I try to export both the files (static and dynamic) to XML 1.0 using acrobat professional and both are having same xml structure.Is there any workaround i can do it using javascript / angularjs. – user_new Mar 31 '17 at 02:07
  • Is there any way to get xfa form data using javascript? – user_new Apr 13 '17 at 06:35
  • In Acrobat, you can access XFA field values using "this.xfa." then the fully qualified field name. For example... var employeeName = this.xfa.form.form1.EmployeeName; – joelgeraci Apr 13 '17 at 14:22
0

The short answer is that XFA forms are not supported right now by pdf.js. See github issue here: https://github.com/mozilla/pdf.js/issues/2373

If all you want is low-level javascript access to your form data (which was my use case), I created a fork of pdf.js here: https://www.npmjs.com/package/@ckhordiasma/pdfjs-dist with the ability to hook into the xfa tree using a getXFA() function that I jammed into the source code.

// filedata: a file blob
const pdfSetup = filedata.arrayBuffer().then(function (buffer) {
    const uint8Array = new Uint8Array(buffer);

    return pdfjs.getDocument({ data: uint8Array }).promise;
  });

const getXFA = pdfSetup.then(function (pdf) {
    return pdf.getXFA();
});

getXFA.then(function(xfa){
    console.log(xfa);
});