0

Well, I have some records in my database and one of those have a character Đ wich is croatian.

The record in the database is correct and when I display it in a grid in JSF/Primefaces the character is diplayed perfectly.

But, when I print it in a PDF using iText the Đ is missing.

I red a lot of manuals including "iText in Action 2nd edition" and try every tip but nothing works.

The manual says that if you put writer.getAcroForm().setNeedAppearances(true); the system will try to render the "image" of the character but it doesnt work.

So far I am tryng with another aproach, I downloaded a Croatian ttf file and this is my current status

 BaseFont CROACIA  =BaseFont.createFont("C:\\CroatiaHrvatska.ttf",BaseFont.WINANSI, BaseFont.EMBEDDED);
CROATA =  new Font(CROACIA, 12);

Document documento = new Document();

ByteArrayOutputStream baos = new ByteArrayOutputStream();

            PdfWriter writer = PdfWriter.getInstance(documento, baos);


            writer.setInitialLeading(20);


            documento.open();



                String frase ="Đaniel";
                documento.add(new Paragraph(frase, CROATA));

Then I close the document and dowload it as PDF, it works but the Đ is still gone (so are most of the text to).

I tried using ISO-8859-1 and UTF-8 as characters as some people suggested in other questions at SO but it doesnt work.

Jordi Castilla
  • 26,609
  • 8
  • 70
  • 109
Alexev
  • 157
  • 2
  • 19
  • This is wrong: `BaseFont.WINANSI`, you should use `BaseFont.IDENTITY_H`. This is wrong: `String frase = "Đaniel";` You should write: `String frase = "\u0110aniel"`. Add a comment if this still doesn't work. In the meantime, I'm going to write an example that works. – Bruno Lowagie Oct 29 '15 at 17:37
  • Awesome, it works perfectly, the TTF I got doesnt seem to have lower case characters, so I will be looking for the ones that windows uses to set up. But so far if everything is uppercase the PDF prints the character. Thank a lot – Alexev Oct 29 '15 at 18:03
  • OK, I'm happy I was able to point you in the right direction. I admit that finding the answer you need in the abundance of questions can be a challenge. I've selected the most important answers in this free book: [The Best iText Questions on StackOverflow](http://pages.itextpdf.com/ebook-stackoverflow-questions.html) – Bruno Lowagie Oct 29 '15 at 18:12

0 Answers0