Last post Oct 14, 2010 10:01 PM by volcano84
Oct 14, 2010 01:24 PM|volcano84|LINK
I'm trying to create a form into pdf file using iTextSharp. I've done some reading about this, and a lot of people suggest creating a template with existing fields, and allow my app to create a copy of that template and load the values into the appropriate
I created a template using Adobe LiveCycle designer 8, and here is my code:
public void ABetterWayToAddFormFieldToExistingPDF( )
string fileNameExisting = @"Template.pdf";
string fileNameNew = @"new.pdf";
using (var existingFileStream = new FileStream(fileNameExisting, FileMode.Open))
using (var newFileStream = new FileStream(fileNameNew, FileMode.Create, FileAccess.Write))
PdfReader reader = new PdfReader(existingFileStream);
PdfStamper stamp = new PdfStamper(reader, newFileStream);
AcroFields fields = stamp.AcroFields;
fields.SetField("Title", "Consumer Relationship Marketing");
fields.SetField("BrandName", "Jack Daniels");
fields.SetField("StartEnd", "01/01/2010 - End Date: 03/31/2010");
stamp.FormFlattening = true; // lock fields and prevent further edits.
stamp.Writer.CloseStream = false;
However, nothing happens, I get a blank page.
So I added breakpoints into my code to debugg, and I get a Count=0 for fields. It seems it is unable to read the fields from the template...
Any ideas why??
Oct 14, 2010 07:02 PM|kuujinbo|LINK
here. if you want to use code like that (AcroFields) you need to create the template with Acrobat,
http://kuujinbo.info/ | HTTP 301
Oct 14, 2010 10:01 PM|volcano84|LINK
Oh ok, I see now, I disn't know there were different types of forms. I'll give it a try with Acrobat.
Thanks for the reply, and thanks for that link, very useful that mail-archive!