How to render Asian characters in a PDF using xhtmlrenderer

1.6k views Asked by At

I was wondering what steps were needed to render Asian characters using the java based xhtmlrenderer (flying saucer) library?

I am wanting to render the following:

<html>
    <body>同名の映画のモデ</body>
</html>

Without any font settings being added to the HTML this renders fine in normal browsers, but I can't find anyway to render this to PDF using the iTextRenderer portion of xhtmlrenderer.

After following various threads on the mailing list, I see lots of posts talking about adding .TTF files from the c:\windows\fonts directory, and I have modified the examples to run on linux ( https://gist.github.com/643173745182c9becc57 ), which shows me various fonts being displayed, but I don't see any Asian glyffs.

Does anyone have any decent pointers, or clean solutions to this problem? Or am I looking at the wrong problem with a really simple solution elsewhere?

2

There are 2 answers

0
anger On

To support the big character set you need to specify a font file that has all those characters in it. Once you've picked a font file you'll need your application to point to that file. I've found that just putting the font files in your font's directory doesn't work.

Try embedding the font too, eg.

renderer.getFontResolver().addFont("your_font_file.ttf", BaseFont.EMBEDDED);

This link has quite a few font files.

0
John On

You can also add the font style information in css.

@font-face {
    font-family: 'your_font_face_name';
    src: url('your_font.ttf');

    -fs-pdf-font-embed: embed;
    -fs-pdf-font-encoding: Identity-H;
        }