Bold not working in Jaspersoft Studio for fonts other than sans serif
Asked Answered
I

5

8

In Jaspersoft Studio I have created a report where I want to display title in bold. If I use sans serif font then it is working correctly. If I use other fonts, bold is displayed in the preview of Jaspersoft Studio, but is not showing when the report is run in the Jasper server. Please help.

Incrustation answered 22/9, 2014 at 15:10 Comment(2)
For proper fonts in PDFs special considerations are necessary. For JasperReports as embedded library font extensions are a solution. I don't know, though, how to do the equivalent on Jasper server.Gateway
See: community.jaspersoft.com/wiki/custom-font-font-extensionDulcy
A
14

Adding maven artifact worked for me

<dependency>
    <groupId>net.sf.jasperreports</groupId>
    <artifactId>jasperreports-fonts</artifactId>
    <version>6.16.0</version>
</dependency>
Alberich answered 18/2, 2021 at 19:24 Comment(0)
C
7

You need to create a jasper fonts extension jar and place it into your classpath both compile-time (while compiling the jrxmls) as well as run-time (while running reports). Here is how the jar (e.g. jasperreports-fonts-5.5.2.jar) should look:

pic1

pic2

The jasperreports_extension.properties should contain few properties to initialize fonts. (I have used spring based fonts initialization. You might need to add couple of spring jars like 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 the fonts.xml to defined what 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 the property "pdfEmbedded" is "true". Finally add the .ttf file for the fonts you want to add to jar.

Couteau answered 8/10, 2014 at 13:3 Comment(0)
S
1

Just go to this site for adding your custom fonts to PDF with Jasper:

Custom Font with the Font Extension

There's an illustrated guide showing you how to create it. Just download a *.ttf file for your font (eg.: Arial.ttf.)

Create the extension and export it as a *.jar file with the help of Eclipse.

Finally add the *.jar to your project. That's it.

Schlep answered 3/1, 2018 at 15:3 Comment(0)
A
0

I've found a solution that worked for me, It may help you too.

  • Problem:

So, I was using Jaspersoft Studio to render a Pdf for my project. I used a bunch of Text Fields and Static Texts. I used "Calibri" font. I found out that when I export my Pdf using Spring Boot service, the bold, italic and bolditalic properties were missing. I found that some of my Static texts had their styling.

  • Solution:

I just opened the Source code of my jrmxl file, and find out that some Text Fileds had:

<textElement markup="styled">
    <font fontName="Calibri" size="9"/>
</textElement>

and some:

<textElement markup="styled">
    <font size="9"/>
</textElement>

The ones without 'fontName="Calibri"' had their styling, so I did it for all the text component. and I left the style component in the header like this:

<style name="boldItalic" fontName="Calibri" isBold="true" isItalic="true"/>
Allegory answered 13/11, 2023 at 8:46 Comment(0)
P
0
  <staticText>
                <reportElement x="1" y="10" width="95" height="20" uuid="55eee6a7-1a94-4d89-a54d-79992a400cd6"/>
                <textElement verticalAlignment="Bottom">
                    <font fontName="Calibri" size="9" isBold="true" pdfFontName="Helvetica-Bold" isPdfEmbedded="true"/>
                </textElement>
                <text><![CDATA[Item Code]]></text>
            </staticText>

Need to add pdfFontName="Helvetica-Bold"

Pacian answered 21/3, 2024 at 13:29 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.