iTextSharp PDF form field validation

江枫思渺然 提交于 2019-12-12 05:39:53

问题


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.


回答1:


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

Your question is answered by an example:

  • Java: http://itextpdf.com/examples/iia.php?id=238
  • C#: http://kuujinbo.info/iTextInAction2Ed/index.aspx?ch=Chapter13&ex=AddJavaScriptToForm

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.



来源:https://stackoverflow.com/questions/13311991/itextsharp-pdf-form-field-validation

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