-
Notifications
You must be signed in to change notification settings - Fork 369
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
The PDF file shows #### for global character #174
Comments
The solution in tutorial works very well. Perhaps this works as well: GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
ge.registerFont(Font.createFont(Font.TRUETYPE_FONT, new File("A.ttf"))); I haven't test yet. |
@danfickle thanks for the reply. I have 2 questions.
|
Hi @danfickle , sorry to disturb you. But I have multiple languages need to support, only CJK font seems not enough. Can I ask when you plan to support global characters ? In fact, I can accept to lose the font style, but can't accept # showing there. Thank you so much for building such a great library. |
@AbnerSui If you need all different languages you just need to declare the font family according and register all needed fonts. E.g. * {
font-family:Arial, "Malgun Gothic", MingLiU, "MS Gothic", "Microsoft JhengHei", "Noto Sans", Hevletica, Sans-serif, serif';
} And of course you muster register all this different font files in the builder. If you register the files with all styles then you also get the different styles. This are the names of the windows font files for this fonts: static final String[] malgun = new String[] { "malgun.ttf", "malgunbd.ttf", };
static final String[] mingliu = new String[] { "mingliu.ttc" };
static final String[] msgothic = new String[] { "msgothic.ttc" };
static final String[] msj = new String[] { "msjh.ttf", "msjhbd.ttf" };
// Only on Win10+, not Win 7
static final String[] msj_ttc = new String[] { "msjh.ttc", "msjhbd.ttc" }; You must locate (in %WINDIR%/fonts or where every) all this fonts and register them in the builder. Note: The sandbox is outdated, don't test this with the sandbox. Having different glyphs and fonts is working fine for me. |
Hi @rototor , thank you for reply.
My java code is like below
But the PDF result is wierd, like below #### The first line became ####, but the style is still there, font-weight:bold; |
Thats to be expected. Only the fonts you specify in font-family are used, in the order you specify them. sans-serif is the builtin default font. It has font styles and all that stuff. But is does not have the glyphs for the Chinese characters, usually it only has a subset of all possible characters. The font-family logic works the following: For each character it is tried to look up a glyph. If a font does not exists, then that font family is skipped (i.e. thats the way font-family is used mostly on the web). But also if that font does not have a glyph for the given character the font is skip. When a font is skipped the next font in the font-family is tried, till a matching character is found. If no font provides a glyph, then OpenHtmlToPDF falls back to print The second and the third line should be the same, shouldn't they? Can you provide a screenshot of how this looks? (you can paste screenshots directly into the comment field of githup) You did not provide a version of simfang for FontStyle.BOLD, so of course the font wont display "bold". You need a font file for each font variation you want. E.g. in the JDK 9 font folder there are different versions of the LucidaBright font:
If you would like to use them you would need to register them all and specify the correct weight and style while registering. It does not matter if you register the file using the API or using the standard CSS font registration rule (see e.g. https://www.w3schools.com/cssref/css3_pr_font-face_rule.asp). In Java2D (Graphics2D etc.) it is possible to let the Java synthesize different font variations. Any typographer would call them dead ugly (in opposite to correctly hand crafted bold or italic fonts), but the API provides the possibility to draw the font with styles the font does not really provide. It then just gets streched (in case of bold) or skewed (in case of italics). PDF on the other side does not provide this possibility. If you don't have a font with a given style, then it wont show up as e.g. bold. You can always use the builtin PDF fonts (e.g. Helvetica) which provides all font variations. But when using custom fonts you need to provide all font variations. |
@rototor thanks very much. Your reply helps to understand the library behavior better. |
Reopen for other users, the comments may help them. |
We found one font from Windows operation system, arialuni.ttf, arial unicode ms, which can be used on almost all languages in the world. Hope this work around can help other users. |
Hi,

I had a try on openhtmltopdf sandbox, but it shows # for global character.
The text was updated successfully, but these errors were encountered: