Search code examples
javaitextxmlworker

PdfPTable element: Japanese characters are not being displayed


I am trying to display Japanese or Arabic characters in a HTML table object and to convert it to a PDF document. E.g.

<table>
   <tr><td>Japanese: ンミタィヴ研理</td></tr>
</table>

Result is just:

Japanese:

When the Japanese content is outside of the table, it is displayed properly in the PDF. I have tried to manipulate the iText PdfPTable content on the Chunk level, and assign a basic font explicitly to the Chunk. But then I will loose other formatting styles like bold, h1, etc. Also if I work with styles the formatting issues will be lost.

I do have, amongst others, 2_wqy-zenhei-0.5.23 as a font package.

So is there any way to tell the iText implementation to display the characters while preserving all formatting made before?


Solution

  • I assume you are using XML Worker to convert your HTML to PDF. If you are still using the old HTML Worker (versions before iText 5), you should upgrade.

    I'm thinking this is a font issue. You have already tested this partially by verifying that your Japanese content is displayed when it's outside the table and by setting the font directly on the PdfPTable content. But maybe there are still some font configuration differences between content within your table and outside of it.

    I have tested with iText 5.5.7 and XML Worker 5.5.7 (current release versions). I don't have the mentioned font package available. So I tested with Arial Unicode.

    I have adjusted your HTML sample like this:

    <table style="font-family: 'Arial Unicode MS'; border:1px solid black">
        <tr><td>Table</td></tr>
        <tr><td>Japanese: ンミタィヴ研理</td></tr>
    </table>
    <p style="font-family: 'Arial Unicode MS'">Japanese in paragraph: ンミタィヴ研理</p>
    

    The resulting PDF looks like this: Japenese text in PDF