本文介绍了JasperReports不会以粗体生成报告的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已阅读或或在


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?

解决方案

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 ireport or jaspersoft-studio 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

这篇关于JasperReports不会以粗体生成报告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-18 09:41