2

I have read JasperReports - Fonts Sample (version 6.2.0) official tutorial to generate my reports the same way they were designed with font styles.

Here's my jasperreports_extension.properties:

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

Here's my fonts.xml:

<?xml version="1.0" encoding="UTF-8"?>
<fontFamilies>
    <fontFamily name="DejaVu Sans">
        <normal>net/sf/jasperreports/fonts/dejavu/DejaVuSans.ttf</normal>
        <bold>net/sf/jasperreports/fonts/dejavu/DejaVuSans-Bold.ttf</bold>
        <italic>net/sf/jasperreports/fonts/dejavu/DejaVuSans-Oblique.ttf</italic>
        <boldItalic>net/sf/jasperreports/fonts/dejavu/DejaVuSans-BoldOblique.ttf</boldItalic>
        <pdfEncoding>Identity-H</pdfEncoding>
        <pdfEmbedded>true</pdfEmbedded>
        <exportFonts>
            <export key="net.sf.jasperreports.html">'DejaVu Sans', Arial, Helvetica, sans-serif</export>
            <export key="net.sf.jasperreports.xhtml">'DejaVu Sans', Arial, Helvetica, sans-serif</export>
        </exportFonts>
        <!--
        <locales>
            <locale>en_US</locale>
            <locale>de_DE</locale>
        </locales>
        -->
    </fontFamily>

    <fontFamily name="DejaVu Serif">
        <normal>net/sf/jasperreports/fonts/dejavu/DejaVuSerif.ttf</normal>
        <bold>net/sf/jasperreports/fonts/dejavu/DejaVuSerif-Bold.ttf</bold>
        <italic>net/sf/jasperreports/fonts/dejavu/DejaVuSerif-Italic.ttf</italic>
        <boldItalic>net/sf/jasperreports/fonts/dejavu/DejaVuSerif-BoldItalic.ttf</boldItalic>
        <pdfEncoding>Identity-H</pdfEncoding>
        <pdfEmbedded>true</pdfEmbedded>
        <exportFonts>
            <export key="net.sf.jasperreports.html">'DejaVu Serif', 'Times New Roman', Times, serif</export>
            <export key="net.sf.jasperreports.xhtml">'DejaVu Serif', 'Times New Roman', Times, serif</export>
        </exportFonts>
    </fontFamily>

    <fontFamily name="DejaVu Sans Mono">
        <normal>net/sf/jasperreports/fonts/dejavu/DejaVuSansMono.ttf</normal>
        <bold>net/sf/jasperreports/fonts/dejavu/DejaVuSansMono-Bold.ttf</bold>
        <italic>net/sf/jasperreports/fonts/dejavu/DejaVuSansMono-Oblique.ttf</italic>
        <boldItalic>net/sf/jasperreports/fonts/dejavu/DejaVuSansMono-BoldOblique.ttf</boldItalic>
        <pdfEncoding>Identity-H</pdfEncoding>
        <pdfEmbedded>true</pdfEmbedded>
        <exportFonts>
            <export key="net.sf.jasperreports.html">'DejaVu Sans Mono', 'Courier New', Courier, monospace</export>
            <export key="net.sf.jasperreports.xhtml">'DejaVu Sans Mono', 'Courier New', Courier, monospace</export>
        </exportFonts>
    </fontFamily>

    <fontFamily name="Arial">
        <normal>net/sf/jasperreports/fonts/arial/arial.ttf</normal>
        <bold>net/sf/jasperreports/fonts/arial/arialbd.ttf</bold>
        <italic>net/sf/jasperreports/fonts/arial/ariali.ttf</italic>
        <boldItalic>net/sf/jasperreports/fonts/arial/arialbi.ttf</boldItalic>
        <pdfEncoding>Identity-H</pdfEncoding>
        <pdfEmbedded>true</pdfEmbedded>
        <exportFonts>
            <export key="net.sf.jasperreports.html">Arial</export>
            <export key="net.sf.jasperreports.xhtml">Arial</export>
        </exportFonts>
    </fontFamily>

    <fontFamily name="Arial Black">
        <normal>net/sf/jasperreports/fonts/arial/ariblk.ttf</normal>
        <pdfEncoding>Identity-H</pdfEncoding>
        <pdfEmbedded>true</pdfEmbedded>
        <exportFonts>
            <export key="net.sf.jasperreports.html">Arial Black</export>
            <export key="net.sf.jasperreports.xhtml">Arial Black</export>
        </exportFonts>
    </fontFamily>

    <!--
        Mapping Java logical fonts, for the sake of HTML export only.
    -->

    <fontFamily name="SansSerif">
        <exportFonts>
            <export key="net.sf.jasperreports.html">'DejaVu Sans', Arial, Helvetica, sans-serif</export>
            <export key="net.sf.jasperreports.xhtml">'DejaVu Sans', Arial, Helvetica, sans-serif</export>
        </exportFonts>
    </fontFamily>
    <fontFamily name="Serif">
        <exportFonts>
            <export key="net.sf.jasperreports.html">'DejaVu Serif', 'Times New Roman', Times, serif</export>
            <export key="net.sf.jasperreports.xhtml">'DejaVu Serif', 'Times New Roman', Times, serif</export>
        </exportFonts>
    </fontFamily>
    <fontFamily name="Monospaced">
        <exportFonts>
            <export key="net.sf.jasperreports.html">'DejaVu Sans Mono', 'Courier New', Courier, monospace</export>
            <export key="net.sf.jasperreports.xhtml">'DejaVu Sans Mono', 'Courier New', Courier, monospace</export>
        </exportFonts>
    </fontFamily>
</fontFamilies>

I placed the fonts in my jar but when I generate the report the font styles still does not appear. Am I missing something?

Alex K
  • 22,315
  • 19
  • 108
  • 236
Philippe Gioseffi
  • 1,488
  • 3
  • 24
  • 41
  • I do not think you have problem with itext library, maybe you have the jasperreports-fonts-6.x.x in your classpath and it is using this instead of your font-extension... This is most probably a classpath problem (probably more then one jasperreports_extension.properties) – Petter Friberg Dec 31 '15 at 11:49
  • See: http://community.jaspersoft.com/wiki/custom-font-font-extension – Dave Jarvis May 09 '16 at 18:19

1 Answers1

4

You need to have the correct path to your xml and ttf files, it follows same style as java package.

Example

If your jasperreports_extension.properties is in the project root folder (that I would suggest since it need to be found by jasper-reports) and you have the fonts.xml and ttf files in a folder that are called fonts.

The reference in jasperreports_extension.properties would be:

net.sf.jasperreports.extension.simple.font.families.myFonts=fonts/fonts.xml

And in fonts.xml

<fontFamily name="DejaVu Sans">
    <normal>fonts/DejaVuSans.ttf</normal>
    <bold>fonts/DejaVuSans-Bold.ttf</bold>
    .....
</fontFamily>

If you still have problem I suggest that you use an IDE like or they will let you automatically generate a jar for the font-extension (including your ttf's).

It will then be enough that you included this jar in your classpath when generating your pdf export.

How to generate font extensions jar using iReport or in JasperSoft Studio

Petter Friberg
  • 21,252
  • 9
  • 60
  • 109
  • What is wrong in my files? I download via maven the jar and modified these files and added my fonts only. And what is even more curious is that I am using Arial and Arial Black with or without bold. I just generated the jar by reading the tutorial you provided and still does not work. – Philippe Gioseffi Dec 30 '15 at 20:34
  • @PhilippeGioseffi Are the jasperreports_extension.properties in root folder, are the fonts.xml deployed in net/sf/jasperreports/fonts/ folder are the ttf deployed in net/sf/jasperreports/fonts/dejavu/ and net/sf/jasperreports/fonts/arial/??? seems strange that you made a package that is the same as jasper report... – Petter Friberg Dec 30 '15 at 20:40
  • If you generate as tutorial it will work make sure that the jar it is in your class path (and remove old jasperreports_extension.properties).... – Petter Friberg Dec 30 '15 at 20:42
  • Naturally the textField need to use a font as indicated in fonts.xml see this question for example of font-extension http://stackoverflow.com/questions/33940126/how-can-i-display-%C2%A3%E2%84%A6%E2%82%AC%CE%B1%CF%80%E2%85%94-in-jasperserver-pdf-using-ireport – Petter Friberg Dec 30 '15 at 20:45
  • and this http://stackoverflow.com/questions/19232826/when-export-a-report-to-pdf-change-the-font/19234053#19234053 – Petter Friberg Dec 30 '15 at 20:46
  • Is it possible to upload my jar here in stackoverflow? – Philippe Gioseffi Dec 30 '15 at 21:48
  • Would you take a look if I place it in Google Drive and share a link here? – Philippe Gioseffi Dec 30 '15 at 21:49
  • Sure, if in the next 10 min. – Petter Friberg Dec 30 '15 at 21:50
  • Done: https://drive.google.com/file/d/0B4dyL0GPpLokbk1QOGgxQW81QWM/view?usp=sharing – Philippe Gioseffi Dec 30 '15 at 21:51
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/99350/discussion-between-petter-friberg-and-philippe-gioseffi). – Petter Friberg Dec 30 '15 at 21:51