difference between ireports Internal preview & pdf preview

早过忘川 提交于 2019-12-08 00:55:27

问题


I have designed the reports in Jaspersoft iRreport Designer 4.0.2

In Internal preview it shows the report in specified font(calibri). Its design and alignment of elements is proper. But in PDF preview its font,alignment of elements are different.


回答1:


  • Try to set pdfFontName and isPdfEmbedded font settings.

The sample:

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

The PDF embedded flag specifies whether an external TrueType font file should be included in the PDF file.

  • Another way is to use the Font Extensions mechanism. This method is recommended by vendor.

The example:

You can generate the font extension for Calibri font with iReport. The result will be the jar file.

The config file (from the generated jar package) will be:

<?xml version="1.0" encoding="UTF-8"?>
<fontFamilies>
   <fontFamily name="Calibri">
       <normal><![CDATA[fonts/calibri.ttf]]></normal>
       <bold><![CDATA[fonts/calibrib.ttf]]></bold>
       <italic><![CDATA[fonts/calibrii.ttf]]></italic>
       <boldItalic><![CDATA[fonts/calibriz.ttf]]></boldItalic>
       <pdfEncoding><![CDATA[Identity-H]]></pdfEncoding>
       <pdfEmbedded><![CDATA[true]]></pdfEmbedded>
       <exportFonts>
               <export key="net.sf.jasperreports.html"><![CDATA[CalibriHtml]]></export>
       </exportFonts>
       <locales>
               <locale><![CDATA[en]]></locale>
       </locales>
   </fontFamily>
</fontFamilies>

The snippet from jrxml file for demonstrating the usage of a new font extension:

<staticText>
    <reportElement x="215" y="26" width="100" height="20"/>
    <textElement>
        <font fontName="Calibri"/>
    </textElement>
    <text><![CDATA[Static text]]></text>
</staticText>

You can use this link for detailed information about using fonts in JasperReports.



来源:https://stackoverflow.com/questions/8268096/difference-between-ireports-internal-preview-pdf-preview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!