Bold font does not work in Jaspersoft Studio for fonts other than sans serif

In Jaspersoft Studio, I created a report in which I want to display the selection in bold. If I use the sans serif font, then it works correctly. If I use other fonts, bold appears in the Jaspersoft Studio preview, but does not appear when the report runs on the Jasper server. Please, help.

+5
source share
2 answers

You need to create a jarper jarper fonts jarper and put it in your classpath, both compile time (when compiling jrxmls) and runtime (when running reports). Here's what the jar looks like (e.g. jasperreports-fonts-5.5.2.jar ):

pic1

pic2

jasperreports_extension.properties should contain several properties for initializing fonts. (I used spring-based font initialization. You may need to add a couple of spring packages, such as spring -core, spring-beans, etc. To your classpath, if not already present.)

net.sf.jasperreports.extension.registry.factory.fonts=net.sf.jasperreports.extensions.SpringExtensionsRegistryFactory net.sf.jasperreports.extension.fonts.spring.beans.resource=fonts/fonts_def.xml 

Now fonts.xml will determine which fonts you want to add.

 <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd"> <bean id="fontBean001" class="net.sf.jasperreports.engine.fonts.SimpleFontFamily"> <property name="name" value="Tahoma"/> <property name="normal" value="fonts/Tahoma.ttf"/> <property name="bold" value="fonts/Tahoma_Bold.ttf"/> <property name="pdfEmbedded" value="true"/> </bean> <bean id="fontBean002" class="net.sf.jasperreports.engine.fonts.SimpleFontFamily"> <property name="name" value="Arial"/> <property name="normal" value="fonts/Arial.ttf"/> <property name="bold" value="fonts/Arial_Bold.ttf"/> <property name="italic" value="fonts/Arial_Italic.ttf"/> <property name="boldItalic" value="fonts/Arial_Bold_Italic.ttf"/> <property name="pdfEmbedded" value="true"/> </bean> </beans> 

Note that the "pdfEmbedded" property is "true" . Finally add the .ttf file for the fonts you want to add to the jar.

+3
source

Just go to this site to add your custom fonts to PDF using Jasper

 https://community.jaspersoft.com/wiki/custom-font-font-extension 

With photos that were mentioned how to create it. Just remove the * .ttf file for your font (ex: Arial.ttf).

Create an extension and export it as a jar using eclipse.

Finally add this jar to your project. Here it is.

0
source

Source: https://habr.com/ru/post/1203148/


All Articles