0

I have a PDF where I add some TextFields.

  var txtFld = new TextField(stamper.Writer, new Rectangle(cRightX - cWidthX, cTopY3, cRightX, cTopY), FieldNameProtocol) { Font = bf, FontSize = cHeaderFontSize, Alignment = Element.ALIGN_RIGHT, Options = PdfFormField.FF_MULTILINE };
  stamper.AddAnnotation(txtFld.GetTextField(), 1);

The ‘bf’ above is a Unicode font that gets embedded in the PDF:

  BaseFont bf = BaseFont.CreateFont(UnicodeFontPath, BaseFont.IDENTITY_H, BaseFont.EMBEDDED); // Create a Unicode font to write in Greek...

Later-on I fill those fields with greek text.

  var acrof = stamper.AcroFields;
  acrof.SetField(fieldName, field.Value/*, field.Value*/); // Set the text of the form field.
  acrof.SetFieldProperty(fieldName, "setfflags", PdfFormField.FF_READ_ONLY, null); // Make it readonly.

When I view the PDF, most of the times the text is missing and if I click on the (invisible) TextField in Acrobat, then the text becomes visible (until it loses focus again).

Any idea what is going on here? I have also tried using non-embedded font, but I get the same thing (although I still seem to get embedded fonts in PDF that are similar to the font I use). I don't know if I am missing sth.

user2173353
  • 4,316
  • 4
  • 47
  • 79
  • 1
    See this, its .Net but should translate to Java very easily, http://stackoverflow.com/a/18445315/231316 – Chris Haas Oct 02 '13 at 21:51
  • @ChrisHaas : Thanks! I will try it soon and let you know how it goes. (Actually I work on .NET too). – user2173353 Oct 07 '13 at 07:53
  • I have tried both of these lines of code and nothing seems to change. I don't know if there is sth to do with the fact that I merge the PDF with another PDF document to get the final PDF... – user2173353 Oct 07 '13 at 12:55
  • 1
    *I don't know if there is sth to do with the fact that I merge the PDF with another PDF document to get the final PDF* - In that case separate the filling of the fields and the merging into two separate steps and check the intermediate result. Then you know whether it's a form filling or a merging issue. – mkl Nov 04 '13 at 12:17

1 Answers1

0

It seemed that I was doing the following at the wrong order (the following is the correct):

acrof.SetFieldProperty(field.Name, "setfflags", PdfFormField.FF_READ_ONLY, null); // Make it readonly.
acrof.SetFieldProperty(field.Name, "textfont", bf, null);
acrof.SetField(field.Name, field.Value/*, field.Value*/); // Set the text of the form field.

At least that's hat I think it was wrong. I have made many changes.

user2173353
  • 4,316
  • 4
  • 47
  • 79