Making fonts available to your JasperReports

From iDempiere en
Jump to navigation Jump to search

If you only use JasperReports on the same machine and your client has access to all the fonts you're using, then this isn't necessary, but it's a good practise to make sure all your fonts are available regardless of what system fonts are installed on the machine that renders the font.

In the source code tree of iDempiere there's a project called

org.adempiere.report.jasper.fonts

This isn't added to the eclipse workspace when running buckminster so you might not have noticed it.

This package is an example of how you pack your fonts to have them available to the reporting engine.

The key issues are:

  • It must be a plugin.
  • Put the TTF-fonts in the source/resources path.
  • Add the following statement to the end of the MANIFEST.MF
Fragment-Host: net.sf.jasperreports.engine;bundle-version="6.3.1"

Add the plugin to the server's/client's run configuration.

One easy way to create a JAR consisting of the fonts used in JasperReports is to create an extension-jar from JasperReports.

This can be done using menu Tools -> Options -> Fonts -> Create Extension

Create-extension.png

NOTE! The created jar must be included in the plugin's classpath.

Add by hieplq when resolve issue IDEMPIERE-1865

When I use org.adempiere.report.jasper.font.demo, I encounter some issue. I fixed it with ticket IDEMPIERE-1865, I want note some my know-how at here.

  • structure of plug-in org.adempiere.report.jasper.font.demo

1. store font file in src folder (or sub folder)

2. make text file with name: fonts-attribute.xml head of file is

<?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">

each font want load, add a block with id is unique value, example with font Arial

<bean id="fontBean133462384309185621" class="net.sf.jasperreports.engine.fonts.SimpleFontFamily">
       <property name="name" value="Arial"/>
       <property name="normal" value="Arial.ttf"/>
       <property name="bold" value="Arial_Bold.ttf"/>
       <property name="italic" value="Arial_Italic.ttf"/>
       <property name="boldItalic" value="Arial_Bold_Italic.ttf"/>
       <property name="pdfEmbedded" value="TRUE"/>
       <property name="pdfEncoding" value="Identity-H"/>
   </bean>

about mean of property please refer http://jasperreports.sourceforge.net/sample.reference/fonts/index.html

Note: to suport unicode. must define property pdfEncoding and value must is "Identity-H" meaning of Identity-H please refer itext document

3. make file with exact name jasperreports_extension.properties contain of file is:

net.sf.jasperreports.extension.registry.factory.fonts=net.sf.jasperreports.extensions.SpringExtensionsRegistryFactory
net.sf.jasperreports.extension.fonts.spring.beans.resource=fonts-attribute.xml

Note value of properties net.sf.jasperreports.extension.fonts.spring.beans.resource is relative path of file in step 2.

4. update by hieplq, when build this plug-in to jar (invoke buckminster create.product action) with setup as above, run idempiere from elipse font load perfect. but when i put this plug-in to build product. font is can't load. after investigate i see it's my fault. file fonts-attribute.xml and jasperreports_extension.properties not include in jar file.

two method to fix it.

 add files fonts-attribute.xml and jasperreports_extension.properties to src folder, it will auto pack to jar.
 Open MANIFEST.MF, open tab build.
 at binary build, tick file fonts-attribute.xml and jasperreports_extension.properties

5. other issue is when make report, at first time, Spring lib must connect to internet to check schema. i fix it by download file spring-beans-2.0.xsd and push it to src folder.

in file fonts-attribute.xml change "http://www.springframework.org/schema/beans/spring-beans-2.0.xsd"
to "spring-beans-2.0.xsd"

See also

See also: https://idempiere.atlassian.net/browse/IDEMPIERE-311 https://idempiere.atlassian.net/browse/IDEMPIERE-1865 http://community.jaspersoft.com/questions/540576/font-support-spring-based-app http://jasperreports.sourceforge.net/sample.reference/fonts/index.html http://jasperreports.sourceforge.net/sample.reference.html