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

newDoc.AcroForm.Fields is Null,not able to read AcroFields
https://forum.pdfsharp.net/viewtopic.php?f=2&t=4251
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 ,
https://drive.google.com/file/d/18OMWprC3u-sSTq87yZ6jUrrRqQt3hcW4/view?usp=sharing

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);
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??

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