PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Fri Jul 12, 2024 2:55 pm

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: Wed Apr 05, 2023 6:39 pm 
Offline

Joined: Wed Apr 05, 2023 6:29 pm
Posts: 1
I'm setting the values of fields using PDF Sharp, and then saving the document. When I open the saved document in Adobe Acrobat, all of the fields are shown filled as they should be. Then I open the form in Chrome or Edge, and then only the text field values are present, and all of the RadioButtons are unset.

Here is a snippet of the code I'm using to set the field values.

Code:
        public void SetFieldValue(string fieldName, string value)
        {
            var acroField = pdfsAcroForm.Fields[fieldName];
            if (acroForm.fields.ContainsKey(fieldName))
            {
                string fieldType = acroForm.fields[fieldName].type;
                if (fieldType == "Text")
                {
                    acroForm.fields[fieldName].value = value;
                    acroField.Value = new PdfString(value);
                }
                else if (fieldType == "RadioButtons")
                {
                    acroForm.fields[fieldName].value = value;
                    acroField.Value = new PdfName("/" + value);
                }
                else if (fieldType == "CheckBoxField")
                {
                    acroForm.fields[fieldName].value = value;
                    PdfCheckBoxField checkbox = acroField as PdfCheckBoxField;
                    checkbox.CheckedName = value;
                    Debug.WriteLine("Setting a CheckBoxField to " + value);
                }
                else if (fieldType == "ComboBox")
                {
                    acroForm.fields[fieldName].value = value;
                    PdfComboBoxField combobox = acroField as PdfComboBoxField;
                    combobox.Value = new PdfString("( )");
                    combobox.Value = new PdfString(value);
                }
            }
        }


And here is the code I'm using when saving the form:
Code:
            // Required to edit Fillable fields in the PDF
            if (pdfsDocument.AcroForm.Elements.ContainsKey("/NeedAppearances") == false)
            {
                pdfsDocument.AcroForm.Elements.Add("/NeedAppearances", new PdfBoolean(true));
            }
            else
            {
                pdfsDocument.AcroForm.Elements["/NeedAppearances"] = new PdfBoolean(true);
            }

            pdfsDocument.Save(fpath);
            pdfsDocument.Close();


Any ideas? I'm pretty confused and I can't think of anything else to try.


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: Google [Bot] and 45 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