Tuesday 26 November 2013

Bold style missing in JasperReports generated pdf

Sounds familiar?
I was struggling a bit trying to bold fonts in the pdf generated by JasperReports.

Of course I set bold attribute in iReport and preview looked good, but when I was generating pdf using Java library, there was no sign of bold style.
Additionally, even I set DejaVu Sans font, in pdf output there was a Helvetica only.
I thought that upgrade JasperReports to 5.5 version would solve the case, but it didn't.
I've also tried attached external fonts like in this post by creating my own jar as a extension to iReport and adding it to classpath.
Next, I have tried to tell Jasper software that I want an embedded fonts in pdf file and set up default font name either in iReport or in Java code like below:
DefaultJasperReportsContext context = DefaultJasperReportsContext.getInstance();
JRPropertiesUtil.getInstance(context).setProperty("", "DejaVu Sans");
JRPropertiesUtil.getInstance(context).setProperty("net.sf.jasperreports.default.pdf.embedded", "true");
JRPropertiesUtil.getInstance(context).setProperty("", "DejaVu Sans");
That didn't help either.
Eventually, it turned out that these few lines were the solution:


One extra dependency was sufficient to bold fonts working with JasperReports pdf!