Custom font embedding does not work in CFDOCUMENT Coldfusion 11

1.7k Views Asked by At

I have a Custom Gotham font that I need to embed in a PDF document. I have googled and tried several ways to do this but it doesn't work. I am trying to get this to work on localhost with CF11 and Apache 2.2 server.

This the code that I have

<!--- The HTML Page code --->
<?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>Test</title>
    <meta http-equiv=Content-Type content="text/html; charset=windows-1252" />
    <meta name=Generator content="Microsoft Word 12 (filtered)" />
    <style type="text/css">
        @font-face
        {
            font-family: 'gothamthin';
            src: url('../fonts/Gotham-Thin.otf');    
        }
    </style>
</head>
<body>
    <span style="font-size:22pt;font-family:'gothamthin'">13 First Street</span>
</body>
</html>

<!--- the PDF Generation Code --->
<cfdocument format="PDF" fontembed="yes" overwrite="true" filename="test.pdf">
    <?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>Test</title>
        <meta http-equiv=Content-Type content="text/html; charset=windows-1252" />
        <meta name=Generator content="Microsoft Word 12 (filtered)" />
        <style type="text/css">
            @font-face
            {
                font-family: "gothamthin";
                src: url('../fonts/Gotham-Thin.otf');    
            }
        </style>
    </head>
    <body>
        <span style='font-size:22pt;font-family:"gothamthin"'>13 First Street</span>
        <br/><br/>
        <span>
            <font face="gothamthin" size="22">
                13 First Street with font tag
            </font>
        </span>
    </body>
    </html>
</cfdocument>

The HTML page version produces the correct output with the desired font. Please see screenshot below:

enter image description here

The PDF version however does not use the custom font.

enter image description here

I opened the PDF in Adobe Reader and checked the Properties->Fonts panel and it does not list the custom font. Please see screenshot below:

enter image description here

I checked the CF Admin Font management section and it shows that the fonts are correctly installed but in a different location that the 1 I have referred in the code. The one I have referred in the code is <app-root>/fonts/*.otf. Please see screenshot below: enter image description here

Also, in the above code, I have used the font family name as gothamthin. If I replace this with gotham-thin(with a hyphen in between which is the same as the name of the font in CF Admin), then I get the below error. I am not sure if this has something to do with anything but this is just an observation I thought I would share.

Detail: The cause of this exception was that: coldfusion.document.spi.DocumentExportException: java.lang.NullPointerException. Message: An exception occurred when performing document processing.

1

There are 1 best solutions below

0
JMFC On

I was running into the exact same issue with the same font. Getting the "NullPointerException" message. Ended up fixing by converting each OTF font to TTF using FontForge. Found some postings saying it doesn't work with OTF fonts even though it shows up correctly in CF admin. I changed the security permissions of the TTF fonts to match the other fonts in the font directory but I am not sure if that was needed- there was a user called "ALL APPLICATION PACKAGES" that I added. I put the TTF fonts in the Windows font directory and then was able to use them in the CFDOCUMENT PDF. I had to use the name the "Font Face" column in the CF admin - the second column in your screenshot. So, I was able to use something like this in the CFDOCUMENT HTML area

<div style="font-family: gotham black;">Quick brown fox</div>
<div style="font-family: gotham medium;">Quick brown fox</div>
<div style="font-family: gotham light;">Quick brown fox</div>

I haven't done much work with it but you may also want to try CFHTMLtoPDF which I believe runs on the WKHTMLTOPDF engine. This tag was introduced in CF11