PDFsharp & MigraDoc Foundation
https://forum.pdfsharp.net/

/NeedAppearances and checkboxes
https://forum.pdfsharp.net/viewtopic.php?f=2&t=4008
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.

Code:
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);
   }
   else
   {
      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

   doc.Save(filename);
}


The pdf file is too big to upload it on the forum, you can find it here.
https://www.file-upload.net/en/download-13701717/BE_Birth_DE_BG.zip.html

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

Page 1 of 1 All times are UTC
Powered by phpBB® Forum Software © phpBB Group
https://www.phpbb.com/