Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Java PDFBox to write Hebrew into PDF

I'm using PDFBox to write text to PDF.
When I write English it works perfectly fine, but when I try to write Hebrew I get gibberish.

I've tried all kind of solutions but nothing seems to work. I tried everything that was described in the following threads: First, Second, Third.

All the above solutions use iText. I need to somehow manage it with PDFBox.

I did see that the use of DictionaryEncoding could work, though I don't understand it. I tried to use it but it doesn't work for Hebrew (Wrote all Hebrew letters from 1488 to 1514).

COSDictionary cosDic = new COSDictionary();

cosDic.setString( COSName.getPDFName("alef"), "1488" ); // First Hebrew letter
.
.
.
cosDic.setString( COSName.getPDFName("tav"), "1514" ); // Last Hebrew letter

font.setEncoding( new DictionaryEncoding( cosDic ) );

Any kind of help would be appreciated.

like image 607
Maor Refaeli Avatar asked Nov 03 '22 07:11

Maor Refaeli


1 Answers

The solution for me was switching to iText.
All the hard work regarding encoding Unicode letters and RTL support in the PDF was implemented by them.
I suppose that if something is too difficult with one library there is probably another library that can do it better.

like image 101
Maor Refaeli Avatar answered Nov 10 '22 00:11

Maor Refaeli