I have a custom font (Rockwell) that I want to use in a PDF and ship with my application.
So I created a jasperreport_extension.properties and a fonts.xml file, which points to my rockwell ttf files.
Creating a pdf with my new font works fine as long as in my fonts.xml file, the path to the rockwell ttf fonts is absolute. E.g. "/home/misja/myProject/src/main/resources/rockwell-regular.ttf".
But having absolute file paths is a no-go when shipping my application, so I want to have classpath-relative paths in my fonts.xml. So just "rockwell-regular.ttf".
However when I do this, generating the pdf gives the following error:
Caused by: org.springframework.beans.PropertyBatchUpdateException: Failed properties: Property 'normal' threw exception; nested exception is net.sf.jasperreports.engine.JRRuntimeException: java.awt.FontFormatException: bad table, tag=90701824; Property 'bold' threw exception; nested exception is net.sf.jasperreports.engine.JRRuntimeException: java.awt.FontFormatException: bad table, tag=-1078132736
at org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:102) ~[spring-beans-3.1.4.RELEASE.jar:3.1.4.RELEASE]
I have debugged JasperReports as far as I could, and I can see that the rockwell-regular.ttf file is found and read when it is read from the classpath. But then eventually an Exception is thrown when the Font is about to be created in FontManager.createFont2D
I attached my jasperreports_extension and my fonts file.
Never mind, the problem was not in the relative url but in the fact that I was reading the ttf from the classpath. My ttf's were copied to the target folder by Maven, but I found out that they were modified by Maven as well, because of resource filtering. I had to add the following snippet to my pom.xml, and now classpath urls are working as they should:
I face into the same problem. But when I am starting with the IDE, your way works. But when I run from jar, I see that the font was not available to the JVM, but I put custom font. How did you solve this problem when you ran it from the jar?
Can't work on font Roboto.