iText pdf library
Website search

How to add a new form from an existing PDF template?

I want create a PDF template from another template. The resulting PDF should still be a template that I can fill out with data. I tried using PdfStamper but the resulting PDF is not template.

Posted on StackOverflow on Sep 11, 2013 by cgnbkm

Let's distinguish two situations, depending on the nature of your PDF template:

You are talking about an XFA template:

In this case, the PDF is merely a container for an XML stream that defines your form. The only way to change it, is by editing the XML. This is best done manually using Adobe LiveCycle Designer, but if you really want to do it programmatically, you can extract the XML from the PDF using iText, manipulate the XML using any type of XML editing software, and finally put back the XML into the PDF using iText. The programmatical solution is very difficult as it requires you to be familiar with the XFA syntax and the XFA specification consists of several hundreds of pages.

You are talking about an AcroForm template

In this case, the root dictionary has an /AcroForm dictionary of which one of the entries is a /Fields array that isn't empty. You can create a PdfReader instance for this template and pass the reader object to PdfStamper. You then create the extra fields you need (text fields, button fields,...) and add them to the stamper using the addAnnotation() method.

If this doesn't answer your question, please clarify, as it's generally not accepted to limit your question to saying "I tried using PdfStamper but the resulting PDF is not template.", you should at least show what you've tried, otherwise you risk that your question will be closed.

Click this link if you want to see how to answer this question in iText 7.

Ready to use iText?

Try our iText 7 Library and add-ons FREE for 30 days. Test your proof of concept, and see if our solution is right for you.

Get my FREE trial

Still have questions? 

We're happy to answer your questions. Reach out to us and we'll get back to you shortly.

Contact us
Stay updated

Join 11,000+ subscribers and become an iText PDF expert by staying up to date with our new products, updates, tips, technical solutions and happenings.

Subscribe Now