CFDocument PDF not showing Japanese data

1.1k views Asked by At

I have created a pdf with Japanese content using CFDocument. But It does not showing the Japanese data. I have used pageEncoding as utf-8. It showing only blank space instead of Japanese data.

I have used the following code,

    <cfcontent type="application/pdf">
    <cfheader name="Content-Disposition" value="attachment;filename=test.pdf">
    <cfprocessingdirective pageencoding="utf-8">
    <cfdocument format="PDF" localurl="yes" marginTop=".25" marginLeft=".25" marginRight=".25" marginBottom=".25" pageType="custom" pageWidth="8.5" pageHeight="10.2">
    <cfoutput>
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
     <title>PDF Export Example</title>
     <style>
      body { font-family: Verdana; }
       </style>
    </head>
    <body>
    <h1>PDF Export Example</h1>
    <p>担当するクライエントの大半は様々な規模の企業だが、カナダの大学や政府関連の研究機関の担当経験もある。
    </p>
    <h1>PDF Export English Example</h1>
    <p>This is an example.
    </p>
    </body>
    </html>
    </cfoutput>
    </cfdocument>

Please help!

2

There are 2 answers

5
Adam Cameron On

It seems Verdana's implementation when used in PDF doesn't support Chinese / Japanese. However it looks like MingLiU does. I just changed it to use that font, and everything worked OK via ColdFusion 10. It still didn't work in Railo, but I assume that's a Railo problem, not a PDF / font problem.

So, anyway, just use a font that specifically supports the glyphs you need to render.

1
Henry On

Something I ran into years ago.

In order to have the Chinese or Japanese characters rendered up correctly in PDF using and , you should first check what's your default locale at ColdFusion Administrator -> Setting Summary -> Java Default Locale. One would have thought CFML will respect custom locale using setLocale(), but it doesn't.

If it is "en_US", edit /lib/cffont.properties. Otherwise, create a /lib/cffont.properties.#locale#(e.g. /lib/cffont.properties.zh_TW ) using cffont.properties as reference.

Replace the font(s) after '=' with system's Chinese font (e.g. MingLiu) for Chinese or system's Japanese font (e.g. MS UI Gothic) for Japanese respectively, assuming ColdFusion is installed on Windows, and client has the respective font(s) installed.

http://henrylearnstorock.blogspot.ca/2010/08/how-to-render-chinese-japanese.html