Jump to content
Changes to the Jaspersoft community edition download ×

Font support in a Spring based app


darth_fader

Recommended Posts

If you're using Spring/Maven and a recent version of Jasper, there is a simple way to add support for TTF fonts like Arial, etc. to your application without including the jasperreports-fonts jar.  

For example, to add Arial fonts to your app, simply add the following files:

src/main/resources:

jasperreports_extensions.properties

--> containing the following

net.sf.jasperreports.extension.registry.factory.fonts=net.sf.jasperreports.extensions.SpringExtensionsRegistryFactory

net.sf.jasperreports.extension.fonts.spring.beans.resource=fonts/fonts.xml

src/main/resources/fonts:

Arial font files (TTF files, can be fount in Windows 7 under C:\Windows\fonts) and fonts.xml spring config

--> containing the following

<?xml version="1.0" encoding="UTF-8"?>

<beans:beans 

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:beans="http://www.springframework.org/schema/beans"

xmlns:jee="http://www.springframework.org/schema/jee"

xsi:schemaLocation="

        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd

        http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.0.3.xsd

        http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-2.0.xsd">

    <beans:bean id="Arial" class="net.sf.jasperreports.engine.fonts.SimpleFontFamily">

        <beans:property name="name" value="Arial"/>

        <beans:property name="normal" value="fonts/arial.ttf"/>

        <beans:property name="bold" value="fonts/arialbd.ttf"/>

        <beans:property name="italic" value="fonts/ariali.ttf"/>

        <beans:property name="boldItalic" value="fonts/arialbi.ttf"/>

        <beans:property name="pdfEncoding" value="Identity-H"/>

        <beans:property name="pdfEmbedded" value="true"/>

 

    </beans:bean>

 

</beans:beans>

  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...