i am trying to write the following PDF template using PDFsharp ,
https://drive.google.com/file/d/18OMWprC3u-sSTq87yZ6jUrrRqQt3hcW4/view?usp=sharingbelow 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);
else
newDoc.AcroForm.Elements.Add("/NeedAppearances", new PdfSharp.Pdf.PdfBoolean(true));
FuncoesAuxiliaresPdf.SetVarsModelo22(acroFields);
if (newDoc.AcroForm != null)
newDoc.Flatten(); // NOTE: doc.AcroForm is null after flattening ! and the pdf is not editable
newDoc.Save(fs);
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??