0

I have an Adobe LiveCycle form which is dynamically composed. We need to load XML data into this form. I tried that with IText and it worked. But after filling the form it has lost its interactivity. How do I fill the form so that it still generates the fields when opened and executes the JavaScript behind it? For the filling I used the following code snippet (template Itext):

    public class FillXFA
{
    public static readonly String DEST = "dest/path";

    public static readonly String SRC = "src/path";
    public static readonly String XML = "xml/path";

    public static void Main(String[] args)
    {
        FileInfo file = new FileInfo(DEST);
        file.Directory.Create();

        new FillXFA().ManipulatePdf(DEST);
    }

    protected void ManipulatePdf(string dest)
    {
        PdfDocument pdfdoc = new PdfDocument(new PdfReader(SRC), new PdfWriter(dest));
        PdfAcroForm form = PdfAcroForm.GetAcroForm(pdfdoc, true);

        XfaForm xfa = form.GetXfaForm();

        // Method fills this object with XFA data under datasets/data.
        xfa.FillXfaForm(new FileStream(XML, FileMode.Open, FileAccess.Read));
        xfa.Write(pdfdoc);

        pdfdoc.Close();
    }
}
Plingoo
  • 1
  • 1
  • Consider using incremental updates (set append mode when creating the `pdfdoc`). – mkl Jun 18 '20 at 05:58
  • I tried, the JS is unfortunately still not executed. – Plingoo Jun 19 '20 at 07:48
  • Can you share the PDF before and after filling? Furthermore, the iText method `xfa.FillXfaForm` simply attempts to *replace the XFA data under datasets/data* - are you sure the JS in your XFA expects and accepts such changes? Apparently sometimes Adobe includes undocumented parts into the XFA XML and requires it to be updated along, consider e.g. [this answer](https://stackoverflow.com/a/57535648/1729265), in particular the `checksum` Bruno inquired about [here](https://stackoverflow.com/q/27470442/1729265). – mkl Jun 19 '20 at 08:37
  • We are now pursuing a different approach that is better suited to our problem. Nevertheless, thanks for your efforts. – Plingoo Jun 23 '20 at 21:42

0 Answers0