matt
matt

Reputation: 219

iTextSharp PDF form field validation

Is is possible to add validation to PDF form fields via iTextSharp.

I currently generate a PDF document, fill editable form fields with values from my database and present the document to the user in a webpage.

PdfReader pdfReader = new PdfReader(template);
PdfStamper pdfStamper = new PdfStamper(pdfReader, writeStream);
AcroFields pdfFormFields = pdfStamper.AcroFields;

pdfFormFields.SetField("field1", myobj.field1value);
...
pdfStamper.Close();

I'd like to be able to dynamically add validation e.g. numeric field min-max values, or custom JavaScript to the field in this document rendering process. I know this is possible when designing the form in Acrobat, but I can't find any methods/fields for accessing these validation fields through iTextsharp.

Upvotes: 0

Views: 2847

Answers (1)

Bruno Lowagie
Bruno Lowagie

Reputation: 77528

When looking for answers, please consult the documentation: "iText in Action".

Your question is answered by an example:

In this example, some custom JavaScript including a validate() method is added to a field/button. This is the JavaScript: http://examples.itextpdf.com/resources/js/extra.js

The JS added as Additional Action (AA) or as action to a Submit button is identical to the JS one would write for HTML.

Upvotes: 1

Related Questions