I remember there's a problem with PDFSharp in AcroForms so have examine the same piece of code carefully with the original distribution of PDFSharp to make sure that the code should work.
Code used
using (var pdf = PdfReader.Open(filename, PdfDocumentOpenMode.Modify))
{
//Enable AcroForm
var acroForm = pdf.AcroForm;
if (!pdf.AcroForm.Elements.ContainsKey("/NeedAppearances"))
{
pdf.AcroForm.Elements.Add("/NeedAppearances", new PdfBoolean(true));
}
else
{
pdf.AcroForm.Elements["/NeedAppearances"] = new PdfBoolean(true);
}
//Fill the form
((PdfTextField)acroForm.Fields["foobar"]).Value = new PdfString("Hello World");
pdf.Save(filename);
}
This worked on .NET Framework 4.6.2 with official PDFSharp. I am sorry if I am still wrong. Please correct me if this is not related to the library iteself.
I remember there's a problem with PDFSharp in AcroForms so have examine the same piece of code carefully with the original distribution of PDFSharp to make sure that the code should work.
Code used
This worked on .NET Framework 4.6.2 with official PDFSharp. I am sorry if I am still wrong. Please correct me if this is not related to the library iteself.