Closed emcintyre-hpe closed 6 months ago
@asolntsev Done!
@emcintyre-hpe I am not an expert in CJK fonts, but at least I can confirm two things:
22:15:49:549 [main] DEBUG ITextFontResolver - Resolved font ArialUnicodeMS/bold/normal: Font ArialUnicodeMS/400/640.0
22:15:49:550 [main] DEBUG ITextFontResolver - Resolved font ArialUnicodeMS/bold/normal: Font ArialUnicodeMS/400
22:15:49:550 [main] DEBUG ITextFontResolver - Resolved font ArialUnicodeMS/bold/normal: Font ArialUnicodeMS/400/640.0
22:15:49:555 [main] DEBUG ITextFontResolver - Resolved font ArialUnicodeMS/normal/normal: Font ArialUnicodeMS/400/320.0
22:15:49:555 [main] DEBUG ITextFontResolver - Resolved font ArialUnicodeMS/normal/normal: Font ArialUnicodeMS/400
22:15:49:555 [main] DEBUG ITextFontResolver - Resolved font ArialUnicodeMS/normal/normal: Font ArialUnicodeMS/400/320.0
22:15:49:556 [main] DEBUG ITextFontResolver - Resolved font ArialUnicodeMS/bold/normal: Font ArialUnicodeMS/400
22:15:49:557 [main] DEBUG ITextFontResolver - Resolved font ArialUnicodeMS/bold/normal: Font ArialUnicodeMS/400/480.0
22:15:49:557 [main] DEBUG ITextFontResolver - Resolved font ArialUnicodeMS/bold/normal: Font ArialUnicodeMS/400
22:15:49:557 [main] DEBUG ITextFontResolver - Resolved font ArialUnicodeMS/bold/normal: Font ArialUnicodeMS/400/480.0
22:15:49:560 [main] DEBUG ITextFontResolver - Resolved font HeiseiKakuGo-W5-H/normal/normal: Font HeiseiKakuGo-W5/400/320.0
22:15:49:560 [main] DEBUG ITextFontResolver - Resolved font HeiseiKakuGo-W5-H/normal/normal: Font HeiseiKakuGo-W5/400
22:15:49:560 [main] DEBUG ITextFontResolver - Resolved font HeiseiKakuGo-W5-H/normal/normal: Font HeiseiKakuGo-W5/400/320.0
So I assume it's some problem with your html or font.
Thanks for looking into it @asolntsev. I've tried everything I can think of, including changing the CJK characters to HTML entities, but it always comes out the same. As far as the font, I'm 99.9% certain it contains at least some of the characters I'm trying to render. So I really can't pinpoint where the characters are getting lost or mis-translated.
Oh my gosh, I swear I tried this already and it had no effect! The encoding of the font has to be BaseFont.IDENTITY_H
:
fonts.addFont("/fonts/ArialUnicodeMS.ttf", "ArialUnicodeMS", BaseFont.IDENTITY_H, true, null);
With that set, the characters are correctly rendered. 🤦
@asolntsev , please let me know if it would be appropriate to add something about this to the documentation or examples. I'd be happy to contribute a PR.
Thank you for sharing! Yes, we could describe it in documentation or Readme.
Or we could even create a test showing how to use cjk font for generating pdf.
Hello,
It seems that I'm not able to generate a PDF where the HTML content contains mixed western/CJK characters. I'm using a Unicode font (Arial Unicode MS), which contains all of the glyphs, but the resulting PDF does not display the CJK characters. I can't tell if it's dropping them or replacing them with something else.
I have a full example project here: https://github.com/emcintyre-hpe/flying-saucer-cjk. HOWEVER, because it uses a proprietary font, the repo is private. Please let me know which contributors here should have access and I will add them.
The example HTML looks like this:
The transformation code:
And here is the resulting PDF