使用itextsharp检查PDF复选框 [英] Checking off pdf checkbox with itextsharp

查看:888
本文介绍了使用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('\n');
    }
    return sb.toString();
}

或者使用 RUPS 。转到窗口小部件注释并查找正常( / N )外观( AP )状态。在我的例子中,他们是 / Off /是

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屋!

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