Get the export value of a checkbox using iTextSharp

后端 未结 4 742
南笙
南笙 2020-12-10 15:57

I\'m working on dynamically filling in the fields on a pdf document using ITextSharp. I\'d like to be able to determine the \"export value\" of the checkbox is from the cod

4条回答
  •  北荒
    北荒 (楼主)
    2020-12-10 16:12

    I couldn't get the answer Mark to work for me because the appearanceDict was always null. Here is a method I wrote that works for the CheckBox and RadioButton controls on the forms I'm dealing with.

    private static string GetAnswerValue(AcroFields.Item f, int i)
    {
        var widg = f.GetWidget(i);
        if (widg == null)
            return null;
        var ap = widg.GetAsDict(PdfName.AP);
        if (ap == null)
            return null;
    
        //PdfName.D also seems to work
        var d = ap.GetAsDict(PdfName.N);
        if (d == null)
            return null;
        var e = d.Keys.FirstOrDefault(n => !n.Equals(PdfName.OFF));
        if (e == null)
            return null;
        return e.ToString().Substring(1);
    }
    

提交回复
热议问题