I’m trying to remove the character limit from form fields before setting them using iTextSharp. I am able to do this manually using Adobe Acrobat but we are dealing with a large number of PDF documents which we are dynamically stamping the form fields using iTextSharp. We did not build these PDF documents, we are just using them as templates which we are populating with data. I’m wondering if there is a way to remove the character limit of a form field using the api so we don’t have to manually check every field for character limits.
I’m guessing this can be done with the SetFieldProperty method but I’m not sure exactly how.
Thanks in advance
It’s easy if you know the internals of the PDF format! The code below is pretty much the same as the code I wrote for a different type of PDF annotation here. That page will explain things in a little more detail and give you some references. But basically the trick is to loop through each page, then loop through each page’s annotations (form fields fall into this category among other things) and then look for text fields that have their maximum length set and just remove that limitation. All of this work is done on a read-only
PdfReaderobject so once we’re done we need to loop through again and write it back out using aPdfWriterof some sort.Below is a full working C# 2010 WinForms app targeting iTextSharp 5.2.1 that shows all of this off. See the comments in the code for further details.