Using System Fonts for Reports PDF Generation

0

I have coded a report that utilizes the system font Times New Roman.

I did not include any font jars but is relying on the idea that Jasper Reports should be able to utilize system fonts.

I used the viewer to view the preview in Jasper Studio, the fonts correctly renders.

When I tried exporting it to PDF, the Font Properties of the generated output shows that it utilized the following font:

Helvetica
   Type: Type1
   Encoding: Ansi
   Actual Font: Arial
   Actual Font Type: TrueType

This is very far from the Times New Roman that I was expecting.

I also tried generating the report via a simple java program and set the logging to trace for the jasperreports class files.

A portion of the log file is pasted in https://pastebin.com/SnTptaHS.

It seems to show that it used java.awtFont using family = Times New Roman (lines 2-7 and lot of other lines). My test font set which is called Test Font seems to be replaced by font with family = Dialog (lines 18-24 and lines 13-36), which honestly, I expect parts of the reports set to the non-existing font set to go bonkers since I did not put the font extension jar in the class file.

So I'm wondering why it still used Helvetica which is the default PDF font.

 

O.S. Windows 10

Jasper Reports version: 6.4.3

 

cutebluangel's picture
Joined: Sep 23 2012 - 8:45pm
Last seen: 3 months 3 weeks ago

3 Answers:

0

You can do that but you'll need to register extra fonts with the iText library. iText is used when exporting to PDF and it doesn't pay attention to the fontName unless the font can be found in the font extension. Considering the amount of effort it takes to register a font with iText or to create a font extension, I'd go with a Font Extension since it's much more streamlined. You can do that right in the studio.

Friendly User's picture
Joined: Oct 8 2009 - 5:59am
Last seen: 5 days 4 hours ago
0

Try to use the deprecated property called pdfFontName in advanced section and select Times Roman there. It defaults to Helvetica. It is highly recommended though not to rely on system fonts and use font extension JAR's instead for a guaranteed result

Friendly User's picture
Joined: Oct 8 2009 - 5:59am
Last seen: 5 days 4 hours ago
0

Do you mean the Times-Roman Standard Type 1 font? I suppose for this case and other Standard Type 1 PDF fonts it is workable. But what if it is fonts like Calibri or Comics Sans? We have no other way to utilize these system fonts than to include in font jars and link to the project classpath that generates my jasper reports?

cutebluangel's picture
Joined: Sep 23 2012 - 8:45pm
Last seen: 3 months 3 weeks ago
Feedback