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

AcroForm fields vs Annotions
https://forum.pdfsharp.net/viewtopic.php?f=2&t=3491
Page 1 of 1

Author:  robberbaron [ Sun Nov 13, 2016 2:16 am ]
Post subject:  AcroForm fields vs Annotions

I have an app where I fill out Form fields using the PdfTextField objects from doc.AcroForm
this works fine.
Code:
            PdfAcroForm myForm = _qaForm.AcroForm;
            if (myForm.Elements.ContainsKey("/NeedAppearances") == false)
                myForm.Elements.Add("/NeedAppearances", new PdfBoolean(true));
            else myForm.Elements["/NeedAppearances"] = new PdfBoolean(true);

            //Getting fields on the pdf form       
            PdfTextField fProjName = (PdfTextField) (myForm.Fields["ProjectName"]);
            fProjName.Font = new XFont("Verdana", 8);


But the template form generally has more fields than I need for a particular page, so I attempt to remove those.
Code:
PdfDocument doc = page.Owner;
            var iRemoved = 0;
            foreach (PdfAnnotation annotation in page.Annotations.ToList().OfType<PdfAnnotation>())
            {
                var annotParent = annotation.Elements[PdfAcroField.Keys.Parent] as PdfReference;
                var title = (annotParent != null)
                    ? ((PdfDictionary)annotParent.Value).Elements[PdfAcroField.Keys.T].ToString()
                    : annotation.Title;
                //if title matches...
                page.Annotations.Remove(annotation);
                        iRemoved++;break;


this appears to work and indeed if I open using PDFXEditor, the fields don't show. But if open using Chrome , PDFXViewer , or try to read the file using PDFSharp, the fields are still there. Until the document is signed, then it appears they are removed.

Any ideas or better way to remove the Fields ?

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