I'm using PDFSharp on .net core 2.2 C#. I'm reading PDF form in my application, than I'm extract form fields and fill them with values. When I save document fields are invisible until I put focus on them (click on them).
Here is code:
PdfDocument document = PdfReader.Open(@"locationOnPC", 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 field = (PdfTextField)(form.Fields["myField"]);
field.Value = new PdfString("12345");
field.ReadOnly = true;
document.Save(@"myLocation");
Here is picture before focus:
And here is picture after focus:
Anyone know what is problem?
This should be inserted after:
PdfAcroForm form = document.AcroForm;
if (form.Elements.ContainsKey("/NeedAppearances"))
form.Elements["/NeedAppearances"] = new PdfBoolean(true);
else
form.Elements.Add("/NeedAppearances", new PdfBoolean(true));