JasperReports 5.6: Could not load the following font

前端 未结 5 971
梦如初夏
梦如初夏 2021-01-05 02:01

I am facing the problem, that JasperReports still cannot find the Arial font.

I created a simple Maven Project with following structure and included it to

相关标签:
5条回答
  • 2021-01-05 02:46

    The problem was the template itself: At one font-tag the <fontName> property was missing:

    Does not work:

    <font size="12" isBold="true" pdfFontName="Arial"/>
    

    Does work:

    <font fontName="Arial" size="12" isBold="true" pdfFontName="Arial" pdfEncoding="Identity-H" isPdfEmbedded="true"/>
    
    0 讨论(0)
  • 2021-01-05 02:53

    In my case, I was using:

    <font fontName="Arial" pdfEncoding="Identity-H" isPdfEmbedded="true"/>
    

    I had to remove pdffontName, the correct font tag is:

    <font fontName="Arial" pdfEncoding="Cp1256"/>
    

    Note I am using a font jar that contains the following .xml file:

        <?xml version="1.0" encoding="UTF-8"?>
    <fontFamilies>
    
       <fontFamily name="Arial">
           <normal><![CDATA[fonts/arial.ttf]]></normal>
           <pdfEncoding><![CDATA[Identity-H]]></pdfEncoding>
           <pdfEmbedded><![CDATA[true]]></pdfEmbedded>
       </fontFamily>
    
    
    </fontFamilies>
    
    0 讨论(0)
  • 2021-01-05 02:55

    Another Solution Worked For Me is:

    JRProperties.setProperty("net.sf.jasperreports.default.pdf.font.name", "Helvetica"); JRProperties.setProperty("net.sf.jasperreports.default.pdf.encoding", "UTF-8"); JRProperties.setProperty("net.sf.jasperreports.default.pdf.embedded", "true");

    If you set parameters from java side, you have to specify font.name and Helvetica saves the day. I tried Arial here but threw the same error.

    0 讨论(0)
  • 2021-01-05 02:56

    You must give the correct name of font for the PDF exporter. Your fonts are presents into the embedded fonts jar. You don't need to put them again into the classes directory ;-)

    There is the correct fonts.xml content for pdf exporter (perhaps the names are case sensitive, be careful) :

    <?xml version="1.0" encoding="UTF-8"?>
    <fontFamilies>
    <fontFamily name="Arial">
        <normal>
          <ttf>fonts/Arial/ARIAL.TTF</ttf>
          <pdf>fonts/Arial/ARIAL.TTF</pdf>
        </normal>
        <bold>
          <ttf>fonts/Arial/ARIALBD.TTF</ttf>
          <pdf>fonts/Arial/ARIALBD.TTF</pdf>
        </bold>
        <italic>
          <ttf>fonts/Arial/ARIALI.TTF</ttf>
          <pdf>fonts/Arial/ARIALI.TTF</pdf>
        </italic>
        <boldItalic>
          <ttf>fonts/Arial/ARIALBI.TTF</ttf>
          <pdf>fonts/Arial/ARIALBI.TTF</pdf>
        </boldItalic>
        <pdfEncoding>Cp1252</pdfEncoding>
        <pdfEmbedded>true</pdfEmbedded>
        <exportFonts>
        </exportFonts>
    </fontFamily>
    </fontFamilies>
    

    I hope this help.

    Regards, T.

    0 讨论(0)
  • 2021-01-05 03:01

    Copy the fonts files (*.ttf) into the folder:

    /path/to/app/WEB-INF/classes/***HERE***
    

    You app will get the fonts from here :)

    0 讨论(0)
提交回复
热议问题