cgfine
cgfine

Reputation: 15

how can I add textfield to the existing pdf template

I want create a pdf template from a another template,the result pdf is still the template then i can fill it with data。 I try to use PdfStamper but the result pdf is not template,any one can help me,thanks.

Upvotes: 1

Views: 656

Answers (1)

Bruno Lowagie
Bruno Lowagie

Reputation: 77606

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 specs for XFA consist 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.

This is shown in the SubscribeForm example. We have an existing template subscribe.pdf and we add several buttons to it, resulting in the new template subscribe_me.pdf.

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

Upvotes: 1

Related Questions