Copy link to clipboard
Copied
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!
Copy link to clipboard
Copied
*Update*
Checking the generated pdf file, it seems to be using the same version iText 2.1.0 to generate the pdf files.
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
I'll give this a try, thanks!
Copy link to clipboard
Copied
Let us know if this fixes the problem. Thanks!
Dave Watts, Eidolon LLC
Copy link to clipboard
Copied
This does make the Asian characters become visible if the correct font is specified, but isn't really viable in my current use case, since the pdf being generated can contain a combination of English + other Asian characters. I would need to determine the language of the text and use the corresponding correct font for it (i.e. Korean uses different font from Chinese/Japanese to be displayed properly, etc.). In CF9 the font is automatically changed to the correct font if it's not possible to display with the specified font.
Copy link to clipboard
Copied
I don't work with double-byte characters that often, but my understanding is that Unicode should represent them all: Chinese, Japanese, Korean, etc. So, the Arial Unicode font should do this as well. And when you use the UTF-8 processing directive instead of a region-specific one like ISO-8859-1 for Latin characters (English, most non-Cyrillic Western European languages) or whatever you use for Japanese or Korean regions, you should have the appropriate characters in the Unicode font. Here's a list of Hangul (Korean) characters in Arial Unicode MS:
https://www.fileformat.info/info/unicode/font/arial_unicode_ms/blockview.htm?block=hangul_jamo
Now, as I said, I have very little real-world experience dealing with these languages in Unicode, so keep that in mind. But the characters are there, and I'd try using a Unicode font and encoding to deliver them if I could.
Dave Watts, Eidolon LLC
Copy link to clipboard
Copied
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>
Copy link to clipboard
Copied
@unknown_disorder , did that help?
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
Copy link to clipboard
Copied
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.
Thank you.
By @KZNB
IPAexMincho is not one of the default fonts in the ColdFusion Administrator. So did you verify beforehand whether it is possible to integrate the font here? Did you install the font yourself? Did you follow the correct steps?
In any case, I would strongly advise you to use standard fonts. For example, Microsoft Yahei font-family for Chinese text and Yu Gothic for Japanese text.
I don't think custom font is working.
I've tried Dave and BKBK ways, but unfortunately situation didn't change.
The standard fonts do work. At least, they do in the example I gave above. You perhaps made a mistake when you tried it.
Your code does work with Yu Gothic. I tested the following, and it worked:
<cfdocument format="pdf" fontembed="true">
<div style="font-family: 'Yu Gothic'">abc あいうえお</div>
</cfdocument>
Copy link to clipboard
Copied
Thank you for your advise.
I heavily use cfdocument and several fonts including IPAexMincho for Asian languages, and there is no problem at all on CF2018 and CF2016.
I would like to use built-in fonts, but must use "User Defined Fonts" for various languages(Traditional Chinese, Khmer etc.).
You can use Yu Gothic is a good news but our systems(CentOS7,8) don't have Yu Gothic as default, so that I installed as "User Defined Fonts" and tried out.
It didn't work however.
To set fonts automatically, located TTF file on /usr/share/fonts/default/TrueType and restart CF, it was displayed on "Current System Fonts", but situation was not changed.
Has anything changed font settings on to use "User Defined Fonts" on CF2021?
Copy link to clipboard
Copied
Hi @KZNB ,
Thank you for sharing that. Quite instructive.
My apologies for presuming that, like me, you're on Windows.
I would suggest that you open a bug ticket.
Copy link to clipboard
Copied
Hi @KZNB ,
I have used your description to create this bug report: https://tracker.adobe.com/#/view/CF-4213775
Please review it and add any comments or feedback you may have.
In any case, vote for the ticket.
Copy link to clipboard
Copied
Hello @BKBK ,
Sorry for late reply.
I should have described OS firstly.
Thank you so much for everythhing.
I deeply appreciate your help.
Copy link to clipboard
Copied
都市開發前後的今昔對比,農田與都市