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

Fill form fields loses formatting
https://forum.pdfsharp.net/viewtopic.php?f=2&t=3108
Page 1 of 1

Author:  mtirion [ Mon May 04, 2015 10:45 am ]
Post subject:  Fill form fields loses formatting

I have a base PDF form that I want to fill in code. There are three fields:
- FieldOne with Helvetica Bold, 18pt
- FieldTwo with Helvetica Bold, 18pt, 180 degrees rotated (upside down)
- FieldThree with standard formatting (Helvetica 14pt)

This is the code I use to fill the form fields:

input = PdfReader.Open(template, PdfDocumentOpenMode.Import);
if (input.AcroForm.Elements.ContainsKey("/NeedAppearances"))
input.AcroForm.Elements["/NeedAppearances"] = new PdfSharp.Pdf.PdfBoolean(true);
else
input.AcroForm.Elements.Add("/NeedAppearances", new PdfSharp.Pdf.PdfBoolean(true));

PdfTextField fld = (PdfTextField)(input.AcroForm.Fields["FieldOne"]);
fld.Text = "New text for FieldOne";
fld = (PdfTextField)(input.AcroForm.Fields["FieldTwo"]);
fld.Text = "New text for FieldTwo";
fld = (PdfTextField)(input.AcroForm.Fields["FieldThree"]);
fld.Text = "New text for FieldThree";

When I open the result in Adobe Acrobat 9:
- The fields are filled, but not visible. When I edit a field the content shows, formatted
- When I print the PDF the fields show, but in Arial 10pt all formatting removed (also the rotation).

What am I doing wrong? Or how can I accomplish this?

Thanks,
Martin

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