Rendering issue for combined font (Japanese & English ) in PDF using cfdocument

572 views Asked by At

I have big trouble with "Combined Fonts" (Japanese & English).

I have to create a PDF document from HTML content which is shown in my website. For that I have used <cfdocument> and implemented the PDF from the HTML content. But my content includes both Japanese & English content and which is appear in a different font in the created PDF than what is on my website. The issue occurred only in the case of combined Japanese & English section.

The requirement is:

  • For English content, the font should be Verdana.
  • For Japanese content, the font should be Simson.

I have implemented the same with Korean, Chinese, French and it's working.

For outputting the special characters, I have added <cfprocessingDirective pageEncoding="utf-8"> above the code. But I still get weird font for the contents in both English and Japanese.

The code I have tried is given below,

        <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; }
          h1 { font-size: 14px; }
          p { font-size: 12px; line-height: 1.25em; margin-left:20px;}
           </style>
        </head>
        <body>
        <h1>PDF Export Example Combined Japanese & English</h1>
        <p>This is an japanese with english example 
        日本人は単純な音素配列論で膠着、モーラ·タイミングの言語、純粋な母音システム、
        音素の母音と子音の長さ、および語彙的に重要なピッチアクセント。語順は通常、粒子が言葉の文法的機能をマ
        ーキング対象オブジェクトと動詞であり、文の構造は、トピック·コメントです。文末粒子は、感情的または強調の影響を追加したり、
        質問を作るために使用されます。名詞は文法的に番号や性別を持たず、何の記事はありません。動詞は主に緊張し、音声ではなく、
        人のために、コンジュゲートされる。形容詞の日本の同等物は、また、結合している。日本人は動詞の形や語彙、話者の相対的な地位、
        リスナーおよび掲げる者を示すと敬語の複雑なシステムを持っています。This is an example.
        </p>
        <h1>PDF Export English Example</h1>
        <p>This is an example.
        </p>
        </body>
        </html>
        </cfoutput>
        </cfdocument>

What else should I do to fix this problem?

Thank you.

1

There are 1 answers

0
lambypie On BEST ANSWER

As per the results I have got and research, I have found that there is an issue with PDF style rendering for English with Japanese content.

So finally I found a solution,

  1. Apply space between the Japanese and English words.
  2. Iterate the whole string (list with space delimiter)
  3. Then It is possible to differentiate the English words from the Japanese words by Regular expression
  4. Apply separate style for English words by wrapping them by span (or any) tag.

I don't know whether this is the proper solution for this issue. This is what I have done for solving the issue.