Get the export value of a checkbox using iTextSharp

后端 未结 4 740
南笙
南笙 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:23

    The best way I found to set a checkbox is:

        void SetCB(AcroFields fields, string F)
        {
            try
            {
                fields.SetField(F, fields.GetFieldItem(F).GetValue(0).GetAsDict(PdfName.AP).GetAsDict(PdfName.N).Keys.Single().ToString().TrimStart('/'));
            } catch { }
        }
    

    error: Sequence contains more than one element

    e.g:

           PdfReader reader = new PdfReader("c:\\qqq\\fl100Y2.pdf");// formFile);
            using (PdfStamper stamper = new PdfStamper(reader, new FileStream("c:\\qqq\\fl100Ynew.pdf", FileMode.Create)))
            {
                AcroFields fields = stamper.AcroFields;
    
                bool set = fields.SetFieldProperty("FillText156", "textsize", 10.0f, null);
                SetCB(fields, "CheckBox24");
                SetCB(fields, "CheckBox24by");
                 fields.SetField("FillText156", "John Doe");
                // flatten form fields and close document
                stamper.FormFlattening = true;
                stamper.Close();
            }
    

提交回复
热议问题