3

I use openhtmltopdf library (version: 0.0.1-RC15). I have a problem with unicode characters. In PDF file I see "#" symbols instead of "ă" and "ș". How I can fix it? Thank you.

Taras Melnyk
  • 3,057
  • 3
  • 38
  • 34

2 Answers2

3

In case it helps, we're using com.openhtmltopdf:openhtmltopdf-pdfbox:1.0.10 and have found a way that works:

        new PdfRendererBuilder()
                .useFastMode()
                .useFont(new File(main.class.getClassLoader().getResource("arial-unicode-ms.ttf").getFile()), "Arial Unicode MS")
                .withW3cDocument(new W3CDom().fromJsoup(Jsoup.parse(html)), null)
                .toStream(os)
                .run();

In the html we have a <style> element that declares some css for the page, in particular:

    font-family: "Arial Unicode MS";

Unicode characters then display as they should.

ndtreviv
  • 3,473
  • 1
  • 31
  • 45
0

I am using openhtmltopdf library. I had character problem too. Turkish characters looks like (İÖĞ -> ###). People already say its about font problem.

I add useFont method like this and download tff file in resource/fonts/

PdfRendererBuilder builder = new PdfRendererBuilder();
builder.useFont(new File(Main.class.getClassLoader().getResource("fonts/ARIAL.TTF").getFile()), "Arial");