Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

含有中文字符的html输出pdf有乱码 #129

Closed
ReliefZk opened this issue Sep 15, 2017 · 2 comments
Closed

含有中文字符的html输出pdf有乱码 #129

ReliefZk opened this issue Sep 15, 2017 · 2 comments

Comments

@ReliefZk
Copy link

有支持中文的计划吗?

@harbulot
Copy link
Contributor

(Although I understand it's not always easy, it would help if you wrote these issues in English.)

Google Translate says that this is what you've written means:

Html output with Chinese characters pdf has garbled

Is there a plan to support Chinese?

It works, but you need to make sure the font you're using supports the characters you're using.

I'm not sure where to find TTF fonts with Chinese characters that you'd like to use, but Google seem to have a few available here: https://fonts.google.com/earlyaccess
(This is just an example, check if the licences are acceptable for your usage purposes.)

Here is an example (with cwTeXFangSong-zhonly.ttf, but it could be something else):

PdfRendererBuilder builder = new PdfRendererBuilder();
// ...
builder.useFont(new FSSupplier<InputStream>() {
    @Override
    public InputStream supply() {
        return new FileInputStream("cwTeXFangSong-zhonly.ttf");
    }
}, "cwTeXFangSong", 400, FontStyle.NORMAL, true);

Then, in your HTML/CSS:

html {
	font-family: "cwTeXFangSong", "Open Sans";
}

(You can use multiple fonts in the font-familiy declaration, and it will fall back to the next font in the list if it can't find the glyph to be drawn in the font.)

@danfickle
Copy link
Owner

Thanks @harbulot
Also see #115 for a complete example of using CJK fonts.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants