Font support in a Spring based app

1

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>

darth_fader's picture
Joined: Mar 7 2010 - 9:45pm
Last seen: 3 days 12 hours ago

0 Answers:

No answers yet
Feedback