Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using iText (iTextSharp) to populate XFA form fields in PDF?

Tags:

c#

pdf

itext

xfa

I need to populate XFA form fields in a PDF (created with Adobe LiveCycle Designer). We're attempting to use iText (actually iTextSharp with C#) to parse the PDF, populate the XFA fields and then save the modified PDF back out.

All the examples I can find with iText (very few iTextSharp examples) talk about modifying AcroForm fields. This PDF does NOT have AcroForm fields and uses XFA only.

Pointers to any non-standard resources would be helpful (I've already done the requisite Googling on the topic and haven't found anything useful).

Code examples here would be awesome from anyone who has actually done what I'm trying to do.

like image 358
Jay Stevens Avatar asked Jun 25 '09 00:06

Jay Stevens


People also ask

How do I combine XFA forms?

They now can be combined without error. If the client would like the forms fields to be active after conversion, take the converted document, open it and go to Forms / Forms Typer. Re-save the document. This will now allow you to open the combined document and fill in the form fields.

How do I convert an XFA to PDF?

To convert XFA PDF to normal PDF, click the Print button, on the Print window that opens, tick Print as Image, and click Print. The XFA form will be converted to a PDF file that you can open with any PDF reader.

How do I know if my form is XFA?

To identify an XFA document, you can check the XFAForm feature in the PDF OutputProfile: boolean xfa = pdf.

What is XFA in Adobe LiveCycle designer?

The XFA forms created in LiveCycle Designer are interactive and dynamic in nature. Adobe recommends editing such PDF forms in their authoring application to retain the form fields and interactive objects.


2 Answers

If you can get a data packet into the PDF, the XFA runtime in Acrobat would populate those fields with the data in the data packet.

If you want to see what one of these looks like, create a form in LiveCycle Designer (comes with Acrobat Pro), add some fields to it, and save it as a dynamic PDF. Open the form in Acrobat and type some values into the fields and save it.

Open the PDF with a tool that lets you peer at the PDF data and you'll find /Catalog/AcroForm/XFA a stream that has an <xfa:datasets> packet with the values you typed. That's what you'll need to create yourself and insert into the PDF.

The XDP spec includes a description of the data packet and the merge algorithm. You can find it here:

http://partners.adobe.com/public/developer/xml/index_arch.html

Alternately, you buy the LiveCycle server from Adobe which lets you do all this programmatically in a number of ways including through web service calls.

like image 111
stevex Avatar answered Sep 20 '22 15:09

stevex


iTextSharp can work with XFA. To remove all doubts, please take a look at sample on iText website:

http://itextpdf.com/examples/iia.php?id=165

like image 44
Dmitry Avatar answered Sep 20 '22 15:09

Dmitry