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.
            Asked
            
        
        
            Active
            
        
            Viewed 2,853 times
        
    3
            
            
        - 
                    3Can it be a font issue? – Alex Shesterov Sep 18 '18 at 10:39
- 
                    Yes, maybe. I've found a similar problem there: https://github.com/danfickle/openhtmltopdf/issues/70 But I don't use any font for this text. – Taras Melnyk Sep 18 '18 at 10:48
- 
                    Can you please try to explicitly define a Unicode font in the CSS, like suggested here: https://github.com/danfickle/openhtmltopdf/issues/20#issuecomment-210754469 ? – Alex Shesterov Sep 18 '18 at 10:55
- 
                    I have ocrb10 font in my html template. @font-face { font-family: ocrb10; src: url('${host}/ocrb10.ttf') } I've tried to add 'unicode-range: U+?????;' to this font-face but it doesn't work I can not find ocrb10 font in Unicode. – Taras Melnyk Sep 19 '18 at 09:26
- 
                    What was the solution in the end? – ndtreviv May 17 '22 at 15:13
- 
                    @ndtreviv the problem has not solved yet – Taras Melnyk May 18 '22 at 08:38
2 Answers
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");
 
    
    
        Alper Karaağaçlı
        
- 31
- 2
