CMDBuild Forum

How do I specify the font file to be used in a PDF report?

Hi CMDBuild Team,

I’m using CMDBuild in Japanese, and I want to run PDF reports in v3.2.2 with Japanese fonts.

In v2.5.0, I could rewrite tomcat/webapps/ROOT/WEB-INF/classes/fonts.xml to specify the font file, but which file should I update and how in the latest version?

Thanks.

Mizuki Iso

Hi,
to use custom fonts in reports you can either install the font on the machine running CMDBuild or configure them with the configuration key “org.cmdbuild.report.fonts”. This is a json list of maps (optionally packed), where each map is a font family configuration.

In example:

[{
    "name":"SansSerif",
    "normal":"org/cmdbuild/report/fonts/arial.ttf",
    "bold":"org/cmdbuild/report/fonts/arialbd.ttf",
    "italic":"org/cmdbuild/report/fonts/ariali.ttf",
    "boldItalic":"org/cmdbuild/report/fonts/arialbi.ttf",
    "pdfEmbedded":"false"
},{
    "name":"Roboto",
    "normal":"org/cmdbuild/report/fonts/Roboto-Regular.ttf",
    "bold":"org/cmdbuild/report/fonts/Roboto-Bold.ttf",
    "italic":"org/cmdbuild/report/fonts/Roboto-Italic.ttf",
    "pdfEmbedded":"false"
}]
1 Like

Hi,

Thank you for the quick answer.
I still can’t solve the problem, so let me ask you a more detailed question.

  1. First, I did three things.
  • edited “$CATALINA_HOME/webapps/ROOT/WEB-INF/classes/org/cmdbuild/config/default_config.properties” as shown below.
    (default_config.properties)
    org.cmdbuild.report.fonts=fonts.json
  • created fonts.json file in the same directory.
    (fonts.json)
    [{
        "name":"IPAGothic",
        "normal":"fonts/ipag.ttf",
        "bold":"fonts/ipag.ttf",
        "italic":"fonts/ipag.ttf",
        "boldItalic":"fonts/ipag.ttf",
        "pdfEmbedded":"false"
    }]
  • created directory “$CATALINA_HOME/webapps/ROOT/WEB-INF/classes/org/cmdbuild/config/fonts” and placed ipag.ttf .
  1. I started tomcat and executed a report, then I received this error message. (like attached image)
{
    "success": false,
    "messages": [
        {
            "level": "ERROR",
            "show_user": false,
            "message": "org.cmdbuild.report.ReportException: error processing report = ReportData{id=2075, code=Cloud Automator}, caused by: org.cmdbuild.report.ReportException: error processing report = ReportData{id=2075, code=Cloud Automator}, caused by: ![Screen Shot 2021-07-06 at 10.25.15|690x314](upload://9YrVJIvrqEgt27m9kxiXcaFztMp.png) com.google.common.util.concurrent.UncheckedExecutionException: org.cmdbuild.report.ReportException: error loading jasper report context, caused by: org.cmdbuild.report.ReportException: error loading jasper report context, caused by: java.lang.RuntimeException: com.fasterxml.jackson.core.JsonParseException: Unrecognized token 'fonts': was expecting 'null', 'true', 'false' or NaN\n at [Source: fonts.json; line: 1, column: 6], caused by: com.fasterxml.jackson.core.JsonParseException: Unrecognized token 'fonts': was expecting 'null', 'true', 'false' or NaN\n at [Source: fonts.json; line: 1, column: 6]"
        }
    ]
}
  1. I rewrote the “fonts.json” file like this, but I got the same error.
{"fonts": [{
    "name":"IPAGothic",
    "normal":"fonts/ipag.ttf",
    "bold":"fonts/ipag.ttf",
    "italic":"fonts/ipag.ttf",
    "boldItalic":"fonts/ipag.ttf",
    "pdfEmbedded":"false"
}]}

Can you tell me what I need to do?

any help would be greatly appreciated.

Hi CMDBuild Team,

I installed the font “IPAexGothic” on the machine running CMDBuild to display Japanese in reports .
When I run “fc-cache” command on the machine, “IPAexGothic” is displayed at the top (=set as highest priority).
And I restarted tomcat but when I run the report in CMDBuild, Japanese is not displayed .

So I decided to try to update the configuration file.

I understood that I should edit tomcat/webapps/ROOT/WEB-INF/classes/org/cmdbuild/config/default_config.properties.
When I set config file as you have shown in your example, it worked. (Report was successfully printed.)

org.cmdbuild.report.fonts=[{ "name": "Arial", "normal": "org/cmdbuild/report/fonts/arial.ttf", "bold": "org/cmdbuild/report/ fonts/arial.ttf", "italic": "org/cmdbuild/report/fonts/arial.ttf", "boldItalic": "org/cmdbuild/report/fonts/arial.ttf", "pdfEmbedded":"" false"}]

But when I specify IPAexGothic as below, it didn’t work.

org.cmdbuild.report.fonts=[{ "name": "IPAexGothic", "normal": "fonts/ipaexg.ttf", "bold": "fonts/ ipaexg.ttf", "italic": "fonts/ipaexg.ttf", "boldItalic": "fonts/ipaexg.ttf", "pdfEmbedded": "false"}]

Running a report with this configuration resulted in the following error

{
    "success": false,
    "messages": [
        {
            "level": "
            ERROR",
            "show_user": false,
            "message": "org.cmdbuild.report.ReportException: 
            Error processing report = ReportData{id=24925, code=FX_contact}, caused by: org.cmdbuild.report: 
            ReportException: error processing report = ReportData{id=24925, code=FX_contact}, caused by: com.google.common.util.concurrent.UncheckedExecutionException: org.cmdbuild.report.ReportException: 
            ReportException: error loading jasper report context, caused by: org.cmdbuild.report: 
            ReportException: error loading jasper report context, caused by: org.cmdbuild.report: 
            Error setting font family property key =< normal > value =< fonts/ipaexg.ttf >, caused by: java.lang.reflect.InvocationTargetException, caused by: net.sf.jasperreports.engine.fonts.InvalidFontException: 
            Error loading font \"fonts/ipaexg.ttf\"., caused by: net.sf.jasperreports.engine.JRException: Input stream not found at: fonts/ipaexg.ttf."
        }
    ]
}

Where should I place the .ttf file?

Thanks.

I resolved the problem by adding font configuration to .jrxml file.
Thank you.

Hi Mizuki,

I have the same problem. Can you give me some help.Thanks

BR

Hi temence,

First, I put the font file in the CMDBuild server:

$ unzip YOURFONT.zip
$ cp /path/to/fonts/truetype/YOURFONT/yourfont.ttf $CATALINA_HOME/webapps/ROOT/WEB-INF/classes/org/cmdbuild/config/fonts/

Then, I added setting to ALL textElements in .jrxml files.

<textElement>
  <font fontName="YOUR_FONT_NAME"/>
</textElement>

And upload report files, then it worked for me.

For example, for Japanese, the following settings were required.

(in server)
$ unzip ipaexg00401.zip
$ cp /path/to/fonts/truetype/ipaexg00401/ipaexg.ttf $CATALINA_HOME/webapps/ROOT/WEB-INF/classes/org/cmdbuild/config/fonts/
(in .jrxml files)
<textElement>
  <font fontName="IPAexGothic" pdfEncoding="Identity-H"/>
</textElement>