PDFsharp & MigraDoc Foundation

newDoc.AcroForm.Fields is Null,not able to read AcroFields
Page 1 of 1

Author:  Saransh12345 [ Fri May 14, 2021 6:15 am ]
Post subject:  newDoc.AcroForm.Fields is Null,not able to read AcroFields

i am trying to write the following PDF template using PDFsharp ,

below is my Sample code i am using ,

using (var fs = new FileStream(ReportPath + newfile, FileMode.Create))
// Get the template and copy it to another document
PdfSharp.Pdf.PdfDocument myTemplate = PdfSharp.Pdf.IO.PdfReader.Open(pdfTemplateMod22, PdfSharp.Pdf.IO.PdfDocumentOpenMode.Modify);
PdfSharp.Pdf.PdfDocument newDoc = (PdfSharp.Pdf.PdfDocument)myTemplate.Clone();

var acroFields = newDoc.AcroForm.Fields; // i am getting a null pointer exception here

//Ensure the new values are displayed
if (newDoc.AcroForm.Elements.ContainsKey("/NeedAppearances"))
newDoc.AcroForm.Elements["/NeedAppearances"] = new PdfSharp.Pdf.PdfBoolean(true);
newDoc.AcroForm.Elements.Add("/NeedAppearances", new PdfSharp.Pdf.PdfBoolean(true));


if (newDoc.AcroForm != null)
newDoc.Flatten(); // NOTE: doc.AcroForm is null after flattening ! and the pdf is not editable

url = "../relatorios/temporarios/" + newfile;

I am Getting AcroForm as Null.
Can any i have idea why my AcroNorm fields are not being Read by PDFsharp??

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