2

I try to export some data from my Java application to a pdf file. I decided to use the pdfBox library,but I realized that I could not do the Greek characters displayed properly into the pdf file. Is there a way to set the encoding? to utf8, or iso-8859-7? I try something like PdFontEncoding or Encoding but I did not get anything.

Thank you for your time.

Aristos
  • 66,005
  • 16
  • 114
  • 150
javment
  • 368
  • 1
  • 5
  • 17

1 Answers1

1

There are two things you would need to do:

  • set the encoding, and
  • provide a font with Greek characters

The inbuilt fonts that most PDF readers have (ie Adobe Reader, OS X Preview, etc) only have the latin1 encoding, which doesn't include Greek characters. See http://libharu.sourceforge.net/fonts.html

My guess is that problem here is not with the encoding, instead the problem is the font. You will need to obtain a font with Greek characters and embed it in the PDF file. Make sure you have a licence to embed the font!

See also Using Java PDFBox library to write Russian PDF

Community
  • 1
  • 1
gutch
  • 6,959
  • 3
  • 36
  • 53
  • Thank you gutch for your answer, I download fonts with greek characters also copy from windows font for example verdana and I try the code `PDFont font = PDTrueTypeFont.loadTTF(doc, "verdana.ttf");` but the result is the same plus that I get the error message when I open the pdf file _font verdana contains bad /widths_ You also said that in first step to _set the encoding_ , how can I do it this? – javment Mar 15 '11 at 11:45
  • That error message has been reported as a bug in version 1.4.0 of PDFBox (see https://issues.apache.org/jira/browse/PDFBOX-954) — maybe 1.3.0 will work for you? – gutch Mar 16 '11 at 00:56
  • As for the question about how to set the encoding, I don't know — I find the PDFBox documentation a bit lacking in this area! – gutch Mar 16 '11 at 00:59
  • The last version is 1.5, I try the 1.4 1.3(I use the pdfbox-app-{version}.jar files) but I get the same error, but the main problem was the encoding. Can you suggest me another pdf library that I can use. If I decide to use _itext_, I must get a commercial license? because my final application is for selling to a customer. Thank you, again! – javment Mar 16 '11 at 09:42
  • You _may_ or _may not_ be required to get a commercial licence for iText, I don't know enough to be able to tell you. And I would put myself at risk if I even suggested an answer... unfortunately it is a question best answered by lawyers! – gutch Mar 17 '11 at 04:22