Your sample works fine with these versions of the JasperReports API: 4.0.1 and 4.1.1 , but I ran into the same problem as with 4.0.2 .
What is the difference?
We can compare two versions of the JRPdfExporter implementation, for example, versions 4.1.1 and 4.0.2.
As you can see, the source code for PdfTextRenderer is different for these two versions, for example, the draw method. This draw () method contains a call to the ColumnText.go () method of the iText structure. This method is used to draw text in a pdf document.
Possible solutions:
You can upgrade your version of the JasperReports library. The last one is 5.2.0, and your sample works with it. Your example works well even with 4.1.1, as I mentioned earlier
You can fix the source code of the PdfTextRenderer class if you cannot update the version of the JR library.
About testing your problem
I wrote a small sample to test your problem. I used the Maven project - to easily switch between versions of the JR libraries.
Java class source code to verify:
public static void testReport() throws JRException { Map<String, Object> params = new HashMap<String, Object>(); params.put("address", "101 HARRIER WAT<br/>OMVILLE<br/>BELLSHIRE<br/>OM1 1HA<br/>"); JasperReport jasperReport = JasperCompileManager.compileReport(reportSource); JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, params, new JREmptyDataSource()); JasperExportManager.exportReportToPdfFile(jasperPrint, outputFileName); }
And the "thin" jrxml test file was:
<?xml version="1.0" encoding="UTF-8"?> <jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="accountStatement" pageWidth="720" pageHeight="1008" columnWidth="680" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" isTitleNewPage="true"> <parameter name="address" class="java.lang.String"/> <queryString> <![CDATA[]]> </queryString> <title> <band height="914" splitType="Stretch"> <textField> <reportElement x="117" y="141" width="297" height="105"/> <textElement markup="html"> <font size="9" isBold="false" pdfFontName="Helvetica"/> </textElement> <textFieldExpression class="java.lang.String"><![CDATA[$P{address}]]></textFieldExpression> </textField> </band> </title> </jasperReport>
source share