Jaspersoft BI Tools

iReport,Jaspersoft Design Studio,Jaspersoft Server, Schema Workbench,Analysis,Dashboards, Self Service BI, Domains,Topics,Ad-Hoc Reports, Jaspersoft ETL, Embedding BI,HTML-5 charts, Fusion Charts,JFree Charts,Drill down reports , Drill down Dashboards,Visualize.js, Performance Tuning, D3 Charts, Jaspersoft Customization

Monday, November 02, 2015

Tip : Tahoma bold font work around when exporting report to PDF from Jasper server 5.x or 6.x

Hello All,

Today, I came across an issue with Tahoma bold font issue while exporting Jasper reports into PDF.
After few hours of R&D, I have got two work around(s). I will be explaining 2 of them and hope this would be helpful if you face the same issue.

Problem Statement : 
PDF Export of bold Tahoma font before work around : 

PDF Export of bold Tahoma font after work around : 

Software used to Test this report : 
1) Jaspersoft Design Studio Professional 6.0.1  (can take 5.x or 6.x).
2) Jasperserver 6.0.1
3) Internet web browsers : IE 11.096 , firefox 41.0.2, Chrome 46.0.2490.80
4) Operating System : Windows 7

Solution 1 : 
1) Check the fonts in windows (Example : C:\Windows\Fonts)
2) Check for the Tahoma font (copy paste to some other location in the computer- to Desktop - you can see two font files copied - one is tahoma.ttf another is tahomabd.ttf )
 NOTE : If your development environment is of Linux flavour get a copy of these ttf files into it. 
3) Upload these files to a folder in Jasper server (Lets say your project folder > and a folder for fonts).

    Example :      
   How to ?

4) Note the path of the bold Tahoma font in the server : /Tahoma_Font_PDF__Bold_Example/Fonts/tahomabd.ttf

In a notepad file text editor write and keep the path to use in JRXML as below

 4) Come back to JRXML file open the report in Source Mode and copy paste the above code for the text fields which you would like to get as bold when exporting to export. 
Before doing it, set font as bold, font type as Tahoma and etc using designer options

Example : 
                <reportElement x="30" y="0" width="525" height="110" uuid="85182593-c9d2-419f-930d-3ee39eccaeaf"/>
                    <font fontName="Tahoma" size="40" isBold="true" pdfFontName="repo:/Tahoma_Font_PDF__Bold_Example/Fonts/tahomabd.ttf"/>
                <textFieldExpression><![CDATA["Tahoma Font  size 40"]]></textFieldExpression>
                <reportElement x="30" y="80" width="524" height="50" uuid="0b480149-7f23-4687-bb5d-fa944e58880e"/>
                    <font fontName="Tahoma" size="30" isBold="true" pdfFontName="repo:/Tahoma_Font_PDF__Bold_Example/Fonts/tahomabd.ttf"/>
                <textFieldExpression><![CDATA["Tahoma Font  size 30"]]></textFieldExpression>
                <reportElement x="30" y="170" width="228" height="30" uuid="2644d5be-3679-44dd-8369-eafed86dffd8"/>
                    <font fontName="Tahoma" size="20" isBold="true" pdfFontName="repo:/Tahoma_Font_PDF__Bold_Example/Fonts/tahomabd.ttf"/>
                <textFieldExpression><![CDATA["Tahoma Font  size 20"]]></textFieldExpression>
                <reportElement x="30" y="240" width="228" height="30" uuid="16f612ed-ceb1-4a6a-b397-65f64d3f8b09"/>
                    <font fontName="Tahoma" size="10" isBold="true" pdfFontName="repo:/Tahoma_Font_PDF__Bold_Example/Fonts/tahomabd.ttf"/>
                <textFieldExpression><![CDATA["Tahoma Font  size 10"]]></textFieldExpression>

 5) Save the report and publish it the server and check the output by exporting into PDF.

 Solution 2: (Hmm...!!! No more screen shots).
1) Go to Preferences in Studio (Menu bar -> Winodw -> Preferences )
2) Under Jasper Studio -> fonts -> Under Fonts -> Click on Add
3) Browse for .ttf files of Tahoma that we saved on our desktop or from windows > fonts of computer location.
4) Check the option " Embbed this font in PDF export".
5) click on Ok then find the "Export" option and click on it. It will generate a jar file with the added .ttf files.
6) Add this jar file to class path of the studio to view the output in the studio ( Your project folder name -> Build path -> Add external jar file).
7) To view the same output in the jasper server, install the generated jar file in lib folder of jasper server  
Example : C:\Jaspersoft\jasperreports-server-6.0.1\apache-tomcat\webapps\jasperserver-pro\WEB-INF\lib
8) Restart the jasper server if it is already running.
9) Publish the report to the server and check the bold font output by exporting the report into PDF.

Another way of using the JAR file 
1) In some environments like where Jasper is integrated - lets say CA PPM Clarity on ondemand systems all the time we may not have the access of installed location of Jasper or Clarity.
In such cases, we have the option of deploying the JAR file directly to the Jasper server from its UI.
#) Right click on the folder > Add jar.
#) Reference the above jar to the report in its Resources.

Otherwise , directly add the JAR file as a resource to the report. ( I have tested it with 5.6 as well 6.x in which it worked for 6.x but not for 5.6).

NOTE : The same procedure we can apply for other font families which jasper directly not supporting as of 6.x version.

I hope this helps some one .!!!
If you like it do share for community developers :-)

Questions/Comments/Suggestions are always welcome :-) :-)

Happy Reporting

Sadakar Pochampalli


No comments:

Post a Comment