Question

I am using jasper report for generating my PDF report. I use following textField configuration in jrxml file.

<textField isStretchWithOverflow="true" isBlankWhenNull="true">
                    <reportElement uuid="ec0e2f1f-82d6-46fd-ba68-394be7f6b015" positionType="Float" stretchType="RelativeToTallestObject" isPrintRepeatedValues="false" mode="Transparent" x="0" y="0" width="100" height="16" isPrintInFirstWholeBand="true" isPrintWhenDetailOverflows="true"/>
                    <box topPadding="2" leftPadding="5" bottomPadding="0" rightPadding="0">
                        <pen lineColor="#757575"/>
                        <topPen lineWidth="0.0"/>
                        <leftPen lineWidth="1.0"/>
                        <bottomPen lineWidth="1.0"/>
                        <rightPen lineWidth="0.0"/>
                    </box>
                    <textElement textAlignment="Left" verticalAlignment="Top" markup="none">
                        <font size="11"/>
                        <paragraph lineSpacing="Single"/>
                    </textElement>
                    <textFieldExpression><![CDATA[$F{firstName}]]></textFieldExpression>
                </textField>

When export PDF, It will show me records like given in below screen-shot. See in first record, there is no single character in second row. Even though it is behaving like text wrapping. I think there must be any solution. Please help me if anybody resolved this issue.
Here I am giving link for whole PDF file.

jasper report exported pdf file screen-sht

Was it helpful?

Solution

The sample PDF uses the font Helvetica (supplied by the PDF viewer) which surely is not used by JasperReports when generically pre-compiling the Report.

If different fonts (having different font metrics) are used like this, fields in the output may turn out to be too big or too small. Thus, I'd advice to explicitly set the font, and to do so using both the fontName and the pdfFontName attributes indicating the same TTF font. Alternatively this can be done more cleanly using JasperReports font extensions. Cf. JasperReports - Fonts Sample for details.

fontName and pdfFontName

E.g., assuming that you are working in a Windows environment and have the appropriate permissions (otherwise simply adapt the path to point to your copy of the font), you can use Arial like this:

<textField isStretchWithOverflow="true" isBlankWhenNull="true">
    <reportElement positionType="Float" stretchType="RelativeToTallestObject" isPrintRepeatedValues="false" mode="Transparent" x="0" y="0" width="100" height="16" isPrintInFirstWholeBand="true" isPrintWhenDetailOverflows="true" uuid="e4335197-b9f6-4d24-9ea0-ef582bcc8393"/>
    <box topPadding="2" leftPadding="5" bottomPadding="0" rightPadding="0">
        <pen lineColor="#757575"/>
        <topPen lineWidth="1.0"/>
        <leftPen lineWidth="1.0"/>
        <bottomPen lineWidth="1.0"/>
        <rightPen lineWidth="1.0"/>
    </box>
    <textElement textAlignment="Left" verticalAlignment="Top" markup="none">
        <font fontName="Arial" size="11" pdfFontName="c:\Windows\Fonts\arial.ttf" isPdfEmbedded="true"/>
    </textElement>
    <textFieldExpression><![CDATA[$F{firstName}]]></textFieldExpression>
</textField>

PDF is a special case in JasperReports because in contrast to most other output formats (which use the system fonts) PDF viewers foremost use one of the standard 14 fonts every PDF viewer must supply or fonts embedded in the respective PDF document; therefore, PDF file generation differs a bit.

font extensions

The cleaner approach requires you to write a file defining your font families with all relevant information, e.g.

<?xml version="1.0" encoding="UTF-8"?>
<fontFamilies>
    <fontFamily name="Verdana">
        <normal>admin/plugins/ireport/config/fonts/verdana.ttf</normal>
        <bold>admin/plugins/ireport/config/fonts/verdanab.ttf</bold>
        <italic>admin/plugins/ireport/config/fonts/verdanai.ttf</italic>
        <boldItalic>admin/plugins/ireport/config/fonts/verdanaz.ttf</boldItalic>
        <pdfEncoding>Identity-H</pdfEncoding>
        <pdfEmbedded>true</pdfEmbedded>
    </fontFamily>
</fontFamilies>

(The fonts referenced from that file (verdana*.ttf) are part of the Microsoft "TrueType core fonts for the Web" collection. The license agreement for their use can be found in eula.html which can currently (as of 2011-04-01) be found at http://www.microsoft.com/typography/fontpack/eula.htm.)

Then you need to tell JasperReports font extensions to retrieve its information from that file as described in the JasperReports font extension sample, i.e. by providing a jasperreports_extension.properties file in the root package containing

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

(the pointed-to fonts.xml is the file mentioned above.)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top