I have been working with PDFSharp to fill in PDFs with AcroForm fields. I am able to set the value of the form fields by using some code similar to this:
PdfTextField txtField = (PdfTextField)oldPDF.AcroForm.Fields["fieldname"];
txtField.Value = new PdfString("my form value");
The problem I have is when I try to change the font for the text that will go into the field. I am able to access the font property of the field, and it lets me set it like this:
txtField.Font = new XFont("Courier New", 16, XFontStyle.Bold);
However, when I open the saved PDF, it defaults the font back to a different font. I have tried using other fonts as well, like "Arial", or "Helvetica", and varying sizes, but nothing seems to stick.
Interesting too, when I open the PDF before I make changes to it with Foxit PhantomPDF I can inspect the form field and see the font is set to Times New Roman
After I fill the PDF and save it, then look at the fields and it will show set to Helvetica 10, no matter what font I try to set in my code.
If I manually edit the form field with Foxit PhantomPDF and change the font that way, it will stick, but I want to do it in code. Is this possible?