Skip to main content
Inspiring
March 16, 2021
Beantwortet

cfreport pdf unable to find registered ttf font, yet cfimage and cfdocument work (RHEL8)

  • March 16, 2021
  • 1 Antwort
  • 1424 Ansichten

Hello all - 

We have recently moved our dev team from our olf CF10 on RHEL6 to CF2021 on RHEL8.  One bit of code we cannot seem to get to function properly is a simple barcode PDF generation.  We have stripped down a test case as barebones as possible and cannot get it to work.  

 

We have the ttf fonts registered in CF administrator (Free 3 of 9 Extended)
We created a very simple CFR file in CF Report Builder, and ticked the box to embed the font
We call the CFR file with <cfreport template="myreport.cfr" format="pdf">

The PDF is generated, however it uses a default font instead of the barcode.

 

If we use the deprecated cfdocument or cfimage tags, the font is happily embedded or renderd, so the font appears to be registered correctly in CF admin.  Also, our cfreport code works fine in CF10.

 

While this simple test would be quite easy to reproduce with an external linunx based PDF generation program, our actual reports are quite complex and would be very time consuming to recreate.

 

We do not see anything pertinent in the log files.   Any suggestions on what might be wrong here?

 

Thanks much,
-Tony

    Dieses Thema wurde für Antworten geschlossen.
    Beste Antwort von GuitsBoy

    So there appears to be an issue with coldfusion 2021 handing off registered fonts/directories to iText which does the backend PDF generation.  But the problem only exists when invoking iText through cfreport, but oddly not when calling it through cfdocument.   

     

    In searching for “itext” within the coldfusion installation dir, it turned up a large changelog document, /opt/ColdFusion2021/cfusion/lib/thirdpartytools/itext_readme.txt. Towards the end of the file, it shows this:

     

    Change 76036
    add "/usr/X11R6/lib/X11/fonts/truetype" to one of these directories FontService will automatically scan for fonts on server start.
    
    Edit //depot/ColdFusion/cf_main/tools/itext/src/com/lowagie/text/FontFactory.java#4
    
    598 count += registerDirectory("/usr/openwin/lib/X11/fonts/TrueType");
    599 count += registerDirectory("/usr/share/fonts/default/TrueType");
    600 count += registerDirectory("/usr/X11R6/lib/X11/fonts/ttf");
    + 601 count += registerDirectory("/usr/X11R6/lib/X11/fonts/truetype");
    602 return count;
    603 }
    604

     

    None of those directories exist on the default RHEL8 installation, however creating the directories (or linking to an existing directory) with the fonts inside allows iText to find the font and correctly embed it in the PDF.  We chose to create a symbolic link from the CF Admin registered font directory to one of the directories referenced above.

     

    ln -s /usr/share/fonts/ttf /usr/share/fonts/default/TrueType

     

    This fixed cfreport's inability to embed (or even specify) fonts in the generated PDF files.

     

    Posting the workaround just in case anyone else runs into a similar issue.  Perhaps Ill try to file a bug report and see if anyone is willing to get this fixed in an update.

    1 Antwort

    GuitsBoyAutorAntwort
    Inspiring
    March 18, 2021

    So there appears to be an issue with coldfusion 2021 handing off registered fonts/directories to iText which does the backend PDF generation.  But the problem only exists when invoking iText through cfreport, but oddly not when calling it through cfdocument.   

     

    In searching for “itext” within the coldfusion installation dir, it turned up a large changelog document, /opt/ColdFusion2021/cfusion/lib/thirdpartytools/itext_readme.txt. Towards the end of the file, it shows this:

     

    Change 76036
    add "/usr/X11R6/lib/X11/fonts/truetype" to one of these directories FontService will automatically scan for fonts on server start.
    
    Edit //depot/ColdFusion/cf_main/tools/itext/src/com/lowagie/text/FontFactory.java#4
    
    598 count += registerDirectory("/usr/openwin/lib/X11/fonts/TrueType");
    599 count += registerDirectory("/usr/share/fonts/default/TrueType");
    600 count += registerDirectory("/usr/X11R6/lib/X11/fonts/ttf");
    + 601 count += registerDirectory("/usr/X11R6/lib/X11/fonts/truetype");
    602 return count;
    603 }
    604

     

    None of those directories exist on the default RHEL8 installation, however creating the directories (or linking to an existing directory) with the fonts inside allows iText to find the font and correctly embed it in the PDF.  We chose to create a symbolic link from the CF Admin registered font directory to one of the directories referenced above.

     

    ln -s /usr/share/fonts/ttf /usr/share/fonts/default/TrueType

     

    This fixed cfreport's inability to embed (or even specify) fonts in the generated PDF files.

     

    Posting the workaround just in case anyone else runs into a similar issue.  Perhaps Ill try to file a bug report and see if anyone is willing to get this fixed in an update.

    BKBK
    Community Expert
    Community Expert
    March 21, 2021

    Hi @GuitsBoy , thanks for sharing that.