5

I am generating a document in Chinese, as well as several other languages, using conditional formatting in Jasper iReport 5. I have iTextAsian.jar in my lib folder. The generated PDF displays Chinese in IE, Firefox, Adobe, Foxit but not Chrome.

In Chrome, all the Chinese characters are missing. I have isPdfEmbedded set to true. Here is the style I am assigning to the Chinese fields. Am I not embeddeding?

    <style name="DynamicFont" isDefault="true" forecolor="#000000" backcolor="#FFFFFF" isBlankWhenNull="false" fontName="SansSerif" isBold="false" isItalic="false" isUnderline="false" isStrikeThrough="false" pdfFontName="Helvetica" isPdfEmbedded="true">
        <conditionalStyle>
            <conditionExpression><![CDATA[$F{locale}.toString().compareToIgnoreCase("am_ET") == 0]]></conditionExpression>
            <style mode="Transparent" forecolor="#000000" fontName="SansSerif" pdfFontName="Amharic-Eng-Regular.ttf" pdfEncoding="Identity-H" isPdfEmbedded="true"/>
        </conditionalStyle>
        <conditionalStyle>
            <conditionExpression><![CDATA[$F{locale}.toString().compareToIgnoreCase("vi_VN") == 0]]></conditionExpression>
            <style mode="Transparent" forecolor="#000000" fontName="SansSerif" pdfFontName="customizationsFonts/Roboto-Regular.ttf" pdfEncoding="Identity-H" isPdfEmbedded="true"/>
        </conditionalStyle>
        <conditionalStyle>
            <conditionExpression><![CDATA[$F{locale}.toString().compareToIgnoreCase("zh_CN") == 0]]></conditionExpression>
            <style mode="Transparent" forecolor="#000000" fontName="SansSerif" pdfFontName="STSong-Light" pdfEncoding="UniGB-UCS2-H" isPdfEmbedded="true"/>
        </conditionalStyle>
    </style>

Is this a Chrome issue or something about the way I am generating the PDF with iReport?

Thank you very much for your time and patience.

John

-- edit --

Here is an example file: [example.pdf]: http://www.easleybooks.com/example.pdf

Alex K
  • 22,315
  • 19
  • 108
  • 236
John
  • 134
  • 1
  • 11
  • Please share an example pdf. – mkl Jan 06 '20 at 20:40
  • @mkl - Here is an example file: [example.pdf]: http://www.easleybooks.com/example.pdf – John Jan 08 '20 at 17:25
  • In spite of you using `isPdfEmbedded="true"` the font is *not* embedded at all (neither subset nor complete) in your sample PDF. Does Chrome probably simply not have access to the font STSong-Light? – mkl Jan 09 '20 at 12:23
  • @mkl - That is what I was worried about, it's odd that Chrome doesn't have access but Firefox, adobe, foxit, chrome under linux do. At any rate, do you have any thoughts on how I might actually embed these cmap files? I can give you the fonts if you like. If you think it's just an issue with Jasper, I can live with it, but I was hoping I could embed those fonts. :( – John Jan 09 '20 at 18:00
  • Additionally, Vietnamese works, but it is a .TTF font. STSong is a .properties file in a JAR and seems to be a "cmap" type of font. I'm not too familiar with fonts, but character map seems to be much different from TTF. I wonder if it even can be embedded? – John Jan 09 '20 at 18:11
  • One obvious difference is the `pdfEncoding="UniGB-UCS2-H"`. Have you tried using `pdfEncoding="Identity-H"` here, too? – mkl Jan 10 '20 at 01:09
  • @mkl - I just tried it and neither Chrome, Firefox, or Adobe display that encoding correctly. There are English letters interspersed which don't belong there. – John Jan 11 '20 at 04:50
  • Ok. I thought it was worth a try. Theoretically, with font subset embedding, it should be possible to support arbitrary glyphs with Identity-H.... – mkl Jan 11 '20 at 07:26

1 Answers1

4

I assume there is no error in your code because If any errors exist, other browsers also can't to display your report correctly. There for you can try these steps to avoid your issue.

  1. Some of your chrome extensions interrupt your report generation. There for disable your chrome extensions.
  2. Open your Chrome developer tools and run your code again and see if there are any error generate in console.
  3. According to this discussion there was a bug exist in chrome that prevent Chinese and Japanese letters to display. There for update your chrome to it latest.
  4. Try to set up setting in the latest chrome by Custom and Control (Wrench icon) > Tools > Encoding >select Unicode (UTF-8)

If these solutions not worked try to update jasper to it latest. I saw there are problems with older versions of jasper when viewing Chinese and Japanese.


Update -: You have used your Chinese font as pdfFontName="STSong-Light" in your code. Try to use any Chinese simplified font to print your pdf because in Firefox your Chinese languages understand as collection of two fonts(Microsoft YaHei and Yu Gothic) , but in Chrome it cannot understand the language even if acrobat extension is enabled. There for you have to change your Chinese font name in your pdf.

Kalana
  • 5,631
  • 7
  • 30
  • 51
  • *"If any errors exist, other browsers also can't to display your report correctly."* - pdf viewers are known to try and fix errors under the hood, but different viewers have different sets of errors they fix. Thus, you're wrong, if the OP produces reports incorrectly, they still may appear as desired in some viewers and differently in others. Nonetheless, it may also simply be a chrome issue, and in that case the steps you mention may help. – mkl Jan 07 '20 at 07:17
  • most of time chrome does not support pdf and even some css and etc. I have faced these kind issues most of the time. There for I used to be use Firefox, but OP need run it on chrome.I saw **lot of discussions** about chrome doesn't support Chinese and Japanese language when report generating. In this case report can viewing in every browsers except chrome then I assume this issue occur because of chrome. – Kalana Jan 07 '20 at 07:51
  • 1
    It is quite *probable* that it's a chrome issue here but it's not *sure* given the presented data, there might also be an issue in the created pdfs. That's all I wanted to point out. – mkl Jan 07 '20 at 09:17
  • Thank you, you are correct @mkl, it could be an issue with the PDF, but Kalana your experience reassures me a bit that it may not be a PDF issue. However, I am not generating the PDF in Chrome, it is generated server side by JasperReports, but I will try disabled extensions regardless. I will mark this as the answer if anything works or if it seems to be a Jasper issue, as I cannot upgrade. – John Jan 07 '20 at 19:11
  • @John it would be great if you shared an example pdf top reproduce the issue with. – mkl Jan 07 '20 at 21:39
  • 1
    @mkl, Kalana - I did all of the things above, no change, but one of the links did make me think I should try it in Chrome under Linux - it does work there. I will try to make a tiny demo of one of these Chinese PDFs tomorrow. – John Jan 07 '20 at 22:12
  • Can you provide example pdf which occur that error. If you add it @mkl will be able to answer your question. – Kalana Jan 08 '20 at 04:56
  • 1
    Here is an example file: http://www.easleybooks.com/example.pdf – John Jan 08 '20 at 17:26
  • @John *"Chrome under Linux - it does work there"* - Does probably your testing Chrome under Linux have access to a font STSong-Light while your original testing Chrome (under Windows?) has not? As mentioned in a comment to your question, your example file does not contain embedded font data... – mkl Jan 09 '20 at 12:25
  • I wish I knew, I'm not sure why Firefox/adobe in windows would have access to this font but Chrome wouldn't. I'm not sure where it would even look for it. It's not a typical TTF, from what I can tell anyway... – John Jan 09 '20 at 18:27
  • Go to **Custom and Control (Wrench icon) > Tools > Encoding > and change language to Chinese**. there are three different types of Chinese language. select one by one and check your pdf. – Kalana Jan 10 '20 at 17:23
  • @Kalana I'm in the newest chrome, but I don't see this wrench icon. I have the 3 vertical dots, then settings, then a wrench icon, but doesn't seem to be the one you are referencing. – John Jan 11 '20 at 04:38
  • Thank you, I will change the font, that seems the only option left. Thank you! I will update if it works, but mark you as the answer now. @mkl - Thank you for all the help as well. – John Jan 12 '20 at 23:27
  • I found an opensource Chinese true type font that seems to embed. Thank you! One day I need to figure out how to embed other fonts or convert them to TTF, my version of Jasper iReport doesn't seem to use many other formats. Thank you!!! – John Jan 13 '20 at 19:03
  • There is not your problem. Chrome needs to be develop further. Since 2011 people complaining this issue, but they unable to give solution for this until now – Kalana Jan 14 '20 at 05:19