PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Tue Mar 19, 2024 4:58 am

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules



Post new topic Reply to topic  [ 1 post ] 
Author Message
PostPosted: Sun Aug 25, 2019 8:28 pm 
Offline

Joined: Sat Aug 24, 2019 5:05 pm
Posts: 1
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 1276 times
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

All times are UTC


Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 32 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Privacy Policy, Data Protection Declaration, Impressum
Powered by phpBB® Forum Software © phpBB Group