iTextSharp PDF表单字段验证 [英] iTextSharp PDF form field validation

查看:219
本文介绍了iTextSharp PDF表单字段验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可以通过iTextSharp向PDF表单字段添加验证.

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

我目前正在生成一个PDF文档,用数据库中的值填充可编辑表单字段,然后在网页中向用户展示该文档.

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();

我希望能够动态添加验证,例如数字字段的最小值-最大值,或者在此文档呈现过程中针对该字段的自定义JavaScript.我知道在Acrobat中设计表单时这是可能的,但是我找不到用于通过iTextsharp访问这些验证字段的任何方法/字段.

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.

推荐答案

在寻找答案时,请查阅文档:"iText in Action".

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

在此示例中,某些自定义JavaScript(包括validate()方法)被添加到字段/按钮.这是JavaScript: http://examples.itextpdf.com/resources/js/extra. js

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

作为附加动作(AA)或作为提交"按钮的动作添加的JS与为HTML编写的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.

这篇关于iTextSharp PDF表单字段验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆