PDFsharp & MigraDoc Foundation

/NeedAppearances and checkboxes
Page 1 of 1

Author:  jvankov [ Sun Aug 25, 2019 8:28 pm ]
Post subject:  /NeedAppearances and checkboxes

I have a form with text fields and checkboxes. When I fill a text field and then open the file with Acrobat Reader I see the text only when I click the text field.
When I set /NeedAppearances to true the text fields are OK, but I can't check checkboxes. Even previously checked checkboxes are unchecked when I open the file with Acrobat Reader.

static void Main(string[] args)//this is 100% of the source. I use the wpf build.
   string filename = @"C:\pdf\BE_Birth_DE_BG.pdf";
   PdfDocument doc = PdfReader.Open(filename, PdfDocumentOpenMode.Modify);
   PdfSharp.Pdf.AcroForms.PdfAcroForm acroForm = doc.AcroForm;

   //setting NeedAppearances to true blocks checkboxes, it's impossible to check them
   //even previously checked checkboxes get unchecked in Acrobar Reader
   bool needAppearances = true;
   if (acroForm.Elements.ContainsKey("/NeedAppearances"))
      acroForm.Elements["/NeedAppearances"] = new PdfBoolean(needAppearances);
      acroForm.Elements.Add("/NeedAppearances", new PdfBoolean(needAppearances));

   PdfTextField textField = (PdfTextField)acroForm.Fields["text_71"];
   PdfString s = new PdfString("ABCDE");
   textField.Value = s;

   PdfCheckBoxField checkboxField = (PdfCheckBoxField)acroForm.Fields["checkbox_100"];
   checkboxField.Checked = true;//does not work when NeedApppearances is true


The pdf file is too big to upload it on the forum, you can find it here.

File comment: The solution(Visual Studio 2017).
FillForm.zip [247.55 KiB]
Downloaded 1000 times

Page 1 of 1 All times are UTC
Powered by phpBB® Forum Software © phpBB Group