Unicode character Issue - openhtmltopdf library

3.5k Views Asked by At

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.

2

There are 2 best solutions below

0
On

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");
0
On

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.