dustin
dustin

Reputation: 199

How to get custom fonts working with jasperserver

When using a custom font with Jaspersoft Studio Professional (free version) and jasperserver community edition (free), it must work in three ways:

  1. in jaspersoft studio professional so we can see what it will look like as it is being designed
  2. when run as HTML report in jasperserver and it must work on browsers on computers which don't have the custom font installed
  3. when exporting the report as a PDF by embedding the font in the PDF

After searching the questions and answers here on stackoverflow and many other places, I can find how to get some of the three cases working, but not all simultaneously. I'm using jasperserver 6.

Upvotes: 1

Views: 8630

Answers (1)

dustin
dustin

Reputation: 199

Here are the steps to get it working in jaspersoft studio and when exporting PDF. It still only looks correct on the HTML report if the font is installed on the browser's computer.

  1. Install the font into jaspersoft studio
    • preferences -> Jaspersoft Studio -> Fonts
    • Add
    • Family Name should be the proper name of the font
    • slect the TrueType font file (or other type) using Browse
    • add bold, italic, etc as desired
    • leave PDF Font Name empty unless you want the font in PDFs to be different
    • PDF Encoding CP1252 (western)
    • check Embed this font in PDF document - this will get it working in PDFs
    • Next >
    • Add mappings for each of the types: html, xhtml, rtf. This will get it working in the browser
    • Finish
    • OK

Now you should be able to select the font in the designer and have it work correctly, even if the font has not been installed to your computer OS directly.

  1. Export the font
    • preferences -> Jaspersoft Studio -> Fonts
    • select the font and click Export
    • name the jar file that will be created
  2. Import the font to jasperserver

    • upload the jar file to the server into an empty directory
    • unpack the jar using unzip
    • edit the fontsfamilynnnnn.xml file to ensure that the <exportFonts> section is correct: <exportFonts> <export key="net.sf.jasperreports.html">Open Sans</export> <export key="net.sf.jasperreports.xhtml">Open Sans</export> <export key="net.sf.jasperreports.rtf">Open Sans</export> </exportFonts>

    • merge the file jasperreports_extension.properties into that same file which exists in /usr/local/tomcat/webapps/jasperserver/WEB-INF/classes/fonts/

    • copy the rest of the files (a directory and an XML file) to the /usr/local/tomcat/webapps/jasperserver/WEB-INF/classes/fonts/ directory
  3. restart the jasperserver

Here are the sources of this information that were most relevant: http://community.jaspersoft.com/wiki/custom-font-font-extension https://mdahlman.wordpress.com/2010/04/16/fonts-in-jasperserver-3-7/

Upvotes: 6

Related Questions