使用 itextsharp 检查 pdf 复选框 [英] Checking off pdf checkbox with itextsharp
本文介绍了使用 itextsharp 检查 pdf 复选框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我尝试了很多不同的方法,但我无法选中复选框!这是我尝试过的:
I've tried so many different ways, but I can't get the check box to be checked! Here's what I've tried:
var reader = new iTextSharp.text.pdf.PdfReader(originalFormLocation);
using (var stamper = new iTextSharp.text.pdf.PdfStamper(reader,ms)) {
var formFields = stamper.AcroFields;
formFields.SetField("IsNo", "1");
formFields.SetField("IsNo", "true");
formFields.SetField("IsNo", "On");
}
它们都不起作用.有什么想法吗?
None of them work. Any ideas?
推荐答案
您不应该猜测"可能的值.您需要使用存储在 PDF 中的值.尝试使用 CheckBoxValues 示例来查找这些可能的值:
You shouldn't "guess" for the possible values. You need to use a value that is stored in the PDF. Try the CheckBoxValues example to find these possible values:
public String getCheckboxValue(String src, String name) throws IOException {
PdfReader reader = new PdfReader(SRC);
AcroFields fields = reader.getAcroFields();
// CP_1 is the name of a check box field
String[] values = fields.getAppearanceStates("IsNo");
StringBuffer sb = new StringBuffer();
for (String value : values) {
sb.append(value);
sb.append('
');
}
return sb.toString();
}
或者使用 RUPS 查看 PDF.转到小部件注释并查找正常 (/N
) 外观 (AP
) 状态.在我的例子中,它们是 /Off
和 /Yes
:
Or take a look at the PDF using RUPS. Go to the widget annotation and look for the normal (/N
) appearance (AP
) states. In my example they are /Off
and /Yes
:
这篇关于使用 itextsharp 检查 pdf 复选框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文