Skip to main content
Participating Frequently
April 29, 2022
Question

Asian characters not showing in pdf files generated using cfdocument in CF 2021

  • April 29, 2022
  • 5 replies
  • 2644 views

After upgrading from Coldfusion 9 to Coldfusion 2021, I'm having issues with displaying Chinese/Japanese characters in the pdf files that are generated using cfdocument from html code. The characters display properly when output as html, but disappear when converted to pdf with cfdocument.

 

Any one else encounter this? Was there any changes to the pdf engine that Coldfusion uses?

 

Thanks!

    This topic has been closed for replies.

    5 replies

    New Participant
    March 17, 2024

    都市開發前後的今昔對比,農田與都市

    KZNB
    New Participant
    May 27, 2022

    Hello,

    I also encountered the same problem.
    Only occurs with ColdFusion2021, not a problem with CF2018 and CF2016, using same code and settings.
    Tried in several environments with CF2021, but got same results that only displayed "abc" when in executing code below:

     

    <cfdocument format="pdf" fontembed="true">
      <div style="font-family:IPAexMincho">abc あいうえお</div>
    </cfdocument>

    ※Of course this "IPAexMincho" font is set up in admin page.

     

    I don't think custom font is working.
    I've tried Dave and BKBK ways, but unfortunately situation didn't change.

    Is it related to the following problem or something?
    https://tracker.adobe.com/#/view/CF-4211764

     

    Or needed special settings other than CF2018?

     

    Thank you.

    BKBK
    Adobe Expert
    May 27, 2022

    Thanks for sharing that, @KZNB . I hope Adobe will reopen the bug ticket. I have added a comment to the ticket, appealing to them to do so.

    KZNB
    New Participant
    May 27, 2022

    Hi @BKBK,

    Thank you very much!

    Hope they will respond in some way.

    BKBK
    Adobe Expert
    May 8, 2022

    To solve the problem, make sure that the HTML code has the appropriate fonts. The following example will show how.

     

    The test files, test0 and test, each has HTML content. The content consists of text in Chinese and in Japanese characters. 

     

    The content in test0 specifies no font. Whereas the content in test specifies the Microsoft Yahei font-family for the Chinese text and the Yu Gothic font-family for the Japanese text . For example:

     

    <p style="font-family: 'Microsoft Yahei'">
    <!--- Text with Chinese characters here --->
    </p>
    
    <p style="font-family: 'Yu Gothic'">
    <!--- Text with Japanese characters here --->
    </p>

     

     

    Remove the TXT extension and place the files in wwwroot.

    When you run the following code, you get a PDF with blank spaces in place of Chinese and Japanese characters:

     

    <!--- test0.html specifies no font --->
    <cfhttp method="get" url="http://127.0.0.1:8500/test0.html" />
    
    <cfdocument format="pdf" fontembed="true">
    	<cfoutput>#cfhttp.filecontent#</cfoutput>
    </cfdocument>

     

     

    When you run the following code, you get a PDF with Chinese and Japanese characters:

     

    <!--- test.html specifies the respective fonts for Chinese and Japanese characters --->
    <cfhttp method="get" url="http://127.0.0.1:8500/test.html" />
    
    <cfdocument format="pdf" fontembed="true">
    	<cfoutput>#cfhttp.filecontent#</cfoutput>
    </cfdocument>

     

      

    BKBK
    Adobe Expert
    May 20, 2022

    @unknown_disorder , did that help?

    Participating Frequently
    November 9, 2022

    sorry, this isn't feasible for my use case because in cases where name is user input, I can't be sure which language it will be in, so I am not able to identify which font to put into the html code.

    Adobe Expert
    April 29, 2022

    Well, that's a big jump from CF 9 to CF 2021! I'd recommend explicitly specifying a Unicode font, and using the CFPROCESSINGDIRECTIVE tag on the page with the CFDOCUMENT tag to explicitly specify UTF-8. Also, use the FONTEMBED attribute to ensure that, well, that Unicode font is embedded. Here's an example from Ben Nadel, who does a lot of CF stuff nowadays.

     

    https://gist.github.com/bennadel/eda36df510b61efc59f2

     

    Dave Watts, Eidolon LLC

     

    Dave Watts, Eidolon LLC
    Participating Frequently
    May 1, 2022

    I'll give this a try, thanks!

    Adobe Expert
    May 2, 2022

    Let us know if this fixes the problem. Thanks!

     

    Dave Watts, Eidolon LLC

    Dave Watts, Eidolon LLC
    Participating Frequently
    April 29, 2022

    *Update*

    Checking the generated pdf file, it seems to be using the same version iText 2.1.0 to generate the pdf files.