Jump to content
We've recently updated our Privacy Statement, available here ×
  • Adding fonts for embedding in PDF


    pereira.joao
    • Features: Charts, Exporters, JasperReports Server, Localization, Reports Version: v8.0.4 Product: JasperReports® Server

    It's Easy

    It is pretty easy to add fonts either to TIBCO Jaspersoft® Studio IDE and to TIBCO JasperReports® Server.

    All you need is the correct form of jar with the fonts. This jar has mainly 3 fundamental concepts:

    1. jasperreports_extension.properties - where is declared the factory for loading the fonts and the location of the font mapping xml within the jar.

    2. fonts.xml - the font mapping xml 

    3. And lastly, the font files themselfes in one of the accepted formats, being TTF, EOT, SVG or WOFF.

    The jar structure should be somewhat like this, considering that the "path" can be any java valid path:

    fonts-extension.jar
        /jasperreports_extension.properties
        /path/fonts.xml
        /path/font/*.TTF (or any of the above file types)
    

    Pay attention for the property declared for containing the factory since the Jaspersoft Studio considers "net.sf.jasperreports.extension.registry.factory.fonts" and the JasperReports Server considers the "net.sf.jasperreports.extension.registry.factory.simple.font.families".

    This can be a source of problems.

    Do not configure the font by adding it through the Jaspersoft Studio preferences - this will render a few different errors.

    Here is an example that will work in both applications by declaring both properties:

    net.sf.jasperreports.extension.registry.factory.fonts=net.sf.jasperreports.engine.fonts.SimpleFontExtensionsRegistryFactory
    net.sf.jasperreports.extension.registry.factory.simple.font.families=net.sf.jasperreports.engine.fonts.SimpleFontExtensionsRegistryFactory
    net.sf.jasperreports.extension.simple.font.families.MyFont=path/fonts.xml
    

    Here is an example of the font.xml for adding source sans pro font:

    <?xml version="1.0" encoding="UTF-8"?>
    <fontFamilies>
        <fontFamily name="Source Sans Pro">
            <normal>path/font/SourceSansPro-Regular.ttf</normal>
            <bold>path/font/SourceSansPro-Bold.ttf</bold>
            <italic>path/font/SourceSansPro-Italic.ttf</italic>
            <boldItalic>path/font/SourceSansPro-BoldItalic.ttf</boldItalic>
            <pdfEncoding>Identity-H</pdfEncoding>
            <pdfEmbedded>true</pdfEmbedded>
        </fontFamily>
    </fontFamilies>

    Now add this jar to your project build path. Jaspersoft Studio will not assume the font, but if you type the font name (the one declared for the font family in the fonts.xml, in this case, "Source Sans Pro") and press enter you will see the font. If you cannot see the font, check your jar structure, because if any of the declared fonts cannot be found, Jasper Studio will not load the jar and will not complain either.

    For using the font on the JasperReports Server, just deploy the fonts jar to

    • jasperreports-server-8.0.4apache-tomcatwebappsjasperserver-proWEB-INFlib

    Or, alternatively, to the

    • jasperreports-server-8.0.4apache-tomcatlib

    The last will make the jar file available to all deployed apps.

    If you are deploying to a different Application Server, like JBOSS or WAS, consider the appropriate documentation.

    For deeper knowledge take a look at jasperreports-fonts-6.18.2.jar located in:

    • jasperreports-server-8.0.4apache-tomcatwebappsjasperserver-proWEB-INFlib

    and refer to the TIBCO Jaspersoft documentation and community.


    User Feedback

    Recommended Comments



    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...