0

I'm facing a problem when filling a PDF form using iTextSharp, I'm using the following code to fill the PDF form:

PdfReader pdfReader = new PdfReader(Properties.Resources.ConfirmationFees);
PdfStamper pdfStamper = new PdfStamper(pdfReader, new FileStream(folderPath + "\\" +fileName, FileMode.Create));

AcroFields pdfFFields = pdfStamper.AcroFields;

pdfFFields.SetFieldProperty("Text1", "textsize", 10.0f, null);

pdfFFields.SetField("Text1", serialNumber.ToString("D6") + "№");

pdfStamper.FormFlattening = false;

// close the pdf
pdfStamper.Close();

When I open the PDF, I have to select the textField and go to Properties, select border color or fill color, and click on "No Color". or just simply add a character to the textField.

I've tried to set the border and background color of the textField to null, but without luck.

So, how can I solve this problem without doing the mentioned way?

Soner Gönül
  • 97,193
  • 102
  • 206
  • 364
Scar
  • 3,460
  • 3
  • 26
  • 51

1 Answers1

2

How did you create your form? If with Open/Libre Office, then the forms are a little bit crappy. You may need to add this line:

pdfFFields.setGenerateAppearances(true);

In your specific C# snippet, that would be:

pdfFFields.GenerateAppearances = true;

See also:

If this doesn't solve your problem, you need to tell us which version of iTextSharp you're using. If it's older than 5.5.1, please upgrade.

Community
  • 1
  • 1
Bruno Lowagie
  • 75,994
  • 9
  • 109
  • 165
  • I'm using iTextSharp V. 5.4.1.0, I've check the `pdfFFields.GenerateAppearances = true;` and it does not solve my problem. Also, I'm not flatten the PDF. I've created the PDF using inDesign, created a textfield in it and using the file as a template for my desktop application. – Scar May 24 '14 at 14:24
  • Share the PDF please, also tell us which font you use. – Bruno Lowagie May 24 '14 at 21:02
  • Solved my issue... A template created with Acrobat Pro worked fine but then I switched to using an alternative editor. The template saved by the non-Adobe editor necessitated the this additional line of code. – Tahbaza Mar 19 '18 at 19:52