How to create and fill out a PDF form

喜欢而已 提交于 2019-12-06 10:32:57

Creating an interactive PDF form using OpenOffice and filling it out using iText (or iTextSharp) is a no-brainer. Please read Chapter 6 of my book, more specifically section 6.3.5 "Filling out a PDF form." The first part of this section is titled "Creating a form with OpenOffice."

It is important that you create real fields and that you give these fields a name. You then have to make sure that you export the document as a PDF form:

As you can see, you need to check the check box next to Create PDF.

I have reasons to believe that you didn't do this, because you say:

based on the samples while i am trying to add , the count of the fields in the pdf template is showing as 0.

You should share your PDF if you want us to check if the count of the fields in that PDF template is 0 or if you are doing something wrong.

If you are doing things correctly (that is: as described in my book), you can fill out the form like this:

PdfReader reader = new PdfReader(template);
PdfStamper stamper = new PdfStamper(reader,
    new FileStream(newFile, FileMode.Create));
AcroFields form = stamper.AcroFields;         
form.SetField(key1, value1);      
form.SetField(key2, value2);      
form.SetField(key3, value3);
...
stamper.Close();

In this snippet key1, key2, key3,... are the values you defined for the fields when you created the form in OpenOffice, and value1, value2, value3,... are the values that you want to add to the fields.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!