cfdocument PDF showing empty for Hindi language string

504 views Asked by At

Here, As per my business logic I should support for all languages. So I've display a string based on country selections.Everything is works fine in my side. But having issue with cfdocument. Here I've come up with my sample / demo code.

Note : I already take a look on CFDocument PDF not showing Japanese data but not help me more in Hindi.

<cfoutput>
    <table border='1px;'>
        <tr>
            <td>Name</td>
            <td>Age</td>
            <td>अनुरोध आईडी</td>
        </tr>
        <tr>
            <td>Kannan</td>
            <td>29</td>
            <td>108</td>
        </tr>
    </table>
</cfoutput>

Which is displayed properly as expected like below image.

enter image description here

But while I'm using that Hindi string inside the cfdocument that not supported one. Like my below image.

<cfoutput>
    <cfdocument format="PDF" overwrite="Yes">
        <table border='1px;'>
            <tr>
                <td>Name</td>
                <td>Age</td>
                <td>अनुरोध आईडी</td>
            </tr>
            <tr>
                <td>Kannan</td>
                <td>29</td>
                <td>108</td>
            </tr>
        </table>
    </cfdocument>
</cfoutput>

enter image description here

Note : I've tried below all type but no luck, I've tried with cfprocessingdirective , cfsetting SetLocale() meta tags cfsavecontents

Please let me know if any suggestions. Thanks in advance !

2

There are 2 answers

0
Sev Roberts On

I've spent many hours getting this right after migrating from CF10 + Windows servers where all the languages we needed had working fonts out of the box, to CF2016 on Linux + Docker, where Chinese, Japanese, Korean and others - I cannot remember if we tested Hindi - were all broken.

Unfortunately there isn't a simple "right" answer to your question, as it depends upon getting two key things correct, and the method will vary slightly depending upon your Server OS, Java version and CF version. But as this is too long for a comment I will risk posting as an answer. The two key points are:

  1. Ensure that suitable fonts are available in a path that CF can access and expects to find them - confirm this using CF Admin -> Fonts
  2. Ensure that your JVM font config is configured for each of the languages that you need to support.

(1) is the easy part and is well documented elsewhere, including on the Ben Nadel link mentioned in an earlier comment - https://www.bennadel.com/blog/2987-testing-foreign-and-unicode-character-rendering-with-the-cfdocument-tag-in-coldfusion.htm Doing that and restarting the CF service will get you to a point where cfdocument will be capable of rendering each font if you explicitly declare it in the CSS. However this is not ideal when you need to support multiple languages and do not know which one applies for a particular element in advance, and/or have a mix of languages within one element.

That's where (2) comes in, you should be able to specify one font in CSS - eg Arial / Helvetica / sans-serif - for an element containing multiple languages eg English and Hindi and in the same paragraph; then Java detects character sequences which fall outside the current font and uses the JVM font config to substitute in a suitable font for those characters without you needing to declare it in your html/css. For Hindi I believe this would typically be Devanagari or Kruti on Windows.

Unfortunately that's the tricky part to get right as it varies by Java version and platform and doesn't seem too well documented. In days gone by, Sun and the OS vendors were pretty good at maintaining a decent base config for us. These days it seems to be an afterthought, particularly on many flavours of Linux.

This link gives an example of how the font config used to work on some environments: https://docs.oracle.com/javase/8/docs/technotes/guides/intl/fontconfig.html Yours may use a different method though. If you search for java [your java platform version] font properties config [your OS] then you should end up on the right path.

1
Kannan.P On

After a long analyzing here I've come with solutions. That is we can download a font ttf file ( Based on your needed languages ). I need Hindi so I've download it from here https://fonts.webtoolhub.com/font-n17979-kruti-dev-010.aspx?lic=1 . And to the following steps.

Step 1: Coldfusion admin - > setting - > font Management.
Step 2: Add a new font management. ( Here you can download the ttf file for needed language then paste it in your local. And mentioned your local path in browser directory options ). FYR : please see my below screen. enter image description here

Step3: Then we can use our needed font in style attribute in HTML. style="font-family:Kruti Dev 010;"

Sample Code :

<cfoutput>
    <div>
        <cfdocument format="PDF" overwrite="Yes" fontembed="true">
            <table border='1px;' style="font-family:Kruti Dev 010;">
                <tr>
                    <td>Name</td>
                    <td>Age</td>
                    <td id='test'>  Request ID  </td>
                </tr>
                <tr>
                    <td id='testVal'>Kannan</td>
                    <td>29</td>
                    <td>108</td>
                </tr>
            </table>
            <p style="font-family:verdana;">This is a heading</p>
            <p style="font-family:courier;">This is a paragraph.</p>

             <p style="font-family:Kruti Dev 010;">This is a paragraph.</p>
        </cfdocument>
    </div>
</cfoutput>

Sample Output in PDF by using cfdocument :

enter image description here

I hope this will help for some one. Thank you !