Hi there -
I have spent the day working through getting a simple .NET Core application setup with pdfsharp. The goal of the application is to simply open a PDF document that contains text boxes and populate those text boxes with specific values.
I've worked through a number of blockers, including:
1) Installing Microsoft.Windows.Compatibility pack (to provide System.Drawing support)
2) Installing the System.Text.Encoding.CodePages to get the proper Encoding type available (1252).
Now, I'm able to open my PDF and navigate to a text field. I can see the objects of the Text Field are fully populated. However, when I try to write a new value the following error gets thrown:
System.NullReferenceException: Object reference not set to an instance of an object.at PdfSharp.Pdf.AcroForms.PdfTextField.RenderAppearance()I'm not sure what I am missing, code below:
Code:
// Open the file
PdfDocument document = PdfReader.Open(@"C:\5.0\Provider\Templates\5.0.pdf", PdfDocumentOpenMode.Modify);
// Get the root object of all interactive form fields
PdfAcroForm form = document.AcroForm;
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
var enc1252 = Encoding.GetEncoding(1252);
PdfTextField testField = (PdfTextField)(form.Fields["body"]);
testField.Text = "012345";
Thanks in advance!
Cheers,
Jason