Problem with chinese characters in PDF

Hi

We have Lucee 5.1 installed on a server running CentOS 6.

Our application generates sales orders as PDF that include Chinese characters.

We have no problems saving Chinese characters to the database or calling them up, and no problem displaying them on screen. The Chinese characters in the PDF are hardcoded.

We are generating the PDF by creating an HTML document and then using CFDOCUMENT to convert it to PDF

To get this to work in Coldfusion, we registered the font pack (SimSun) in the Coldfusion administrator.

We cannot get this font to register in Lucee.

Here is a simplified version of the code that is generating the PDF

<cfprocessingdirective pageencoding="utf-8">

<cfdocument format="pdf" orientation="portrait" pagetype="a4">
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>SimSun Test</title>
<style>
body,td,th{font-family:SimSun,Lucida Sans Unicode, sans-serif,Helvetica, Arial; font-size:12px;}
</style>
</head>
<body>

地址:Address:<br>
电话 Tele:<br>
传真 Fax:<br>
开户行:Bank name:<br>
银行账号 Bank Account<br>

</body>
</html>

</cfdocument>  

This page renders the test as HTML
http://lucee.myswift.online/test/SimSun2.cfm

This page generates the test as PDF
http://lucee.myswift.online/test/SimSun.cfm

So far we have tried:

  • creating opt/lucee/lib/fonts.jar with the font in it
  • creating opt/lucee/jdk/jre/jre/lib/fonts/SimSun.ttf

Any tips (preferably to just get this working like it should and not having to use something like wkhtml2pdf

2 Likes

We have solved this problem ourselves. Lucee 5 does not install a font.jar file itself (I think 4.5 and earlier did)

So we had to create it ourselves… but it has to be created in a specific way with specific properties

But it is now working for us.

It would be awesome if you could give an example of how you solved this problem :slight_smile:

In order to add a custom font to Lucee (version 5.0/5.1), you need to create a file called fonts.jar.

The fonts.jar file is essentially a zip file containing a specific files structure as below:

fonts/
fonts/pd4fonts.properties
fonts/SimSun.ttf

It is quite important that the fonts/ directory exists in this archive file, and that the files reside within it.

The pd4fonts.properties is a file specifying the name(as used by Lucee) of the font and the file which it is associated with.

Our pd4fonts.properties file contains this one line:

SimSun=SimSun.ttf

If you need to load more fonts, you can add them all into this same jar file, listing each of the fonts on a new line within the pd4fonts.properties file.

Note: If your font name contains spaces, they need to escaped in the pd4fonts.properties file:

eg. Times\ New\ Roman.ttf

Once the jar file has been created, copy it into the Lucee lib directory, in this case it would be:

/opt/lucee/lib/

Make sure the file has the same permissions as the existing lucee-xxx.jar file in the same location.

Restart the Lucee service to load the new fonts file.

Travis Catlett
Senior Developer
Rone Webtech

3 Likes

not worked, can you share your fonts.jar ???

The maximum upload size for this site is 3Mb and the file is 5Mb so please download it here.
You might have to modify the structure of the file to deal with your server.

http://randd.myswift.online/help/fonts.jar

2 Likes

thank you very much, it’s 100% worked