manash
manash

Reputation: 7106

Fill PDF form field with Hebrew text (RTL)

I tried to use iText 7 community to check if it supports filling PDF form fields in Hebrew. For some reason, I can't make it work.

Here is the code I'm using:

PdfAcroForm form = PdfAcroForm.getAcroForm(pdfDoc, false);
form.setGenerateAppearance(true);

form.getField("test").setValue("\u05de\u05d9\u05db\u05d0\u05dc");

form.flattenFields();
pdfDoc.close();

The PDF is a blank PDF page including only one text field with the following properties:

I tried with and without flattening fields.

When fields are not flattened, after opening the resulting PDF using Acrobat Reader, I see my field but it is empty. Only after I click on the field, the content of the field appears correctly. When I view the PDF on Chrome, the field doesn't appear (or it may be there but no text inside).

When fields are flattened, after opening the resulting PDF using Acrobat Reader, the field doesn't appear at all.

I precise that I created the PDF using Acrobat DC.

Any idea what is going on here?


EDIT: The test PDF can be downloaded from here

Upvotes: 1

Views: 1461

Answers (1)

user967710
user967710

Reputation: 2007

Try creating a font (not all fonts support IDENTITY_H, but Arial does). On windows this will look like this:

        PdfFont f = PdfFontFactory.createFont("C:\\windows\\fonts\\arial.ttf", PdfEncodings.IDENTITY_H, true);

And then set the font to field:

form.getField("test").setValue("\u05de\u05d9\u05db\u05d0\u05dc").setFont(f);

This worked for me

Upvotes: 0

Related Questions