The problem of aligning text with a report created as a PDF file using markup = "html" using iReport

I have the following data to be printed in PDF,

101 HARRIER WAY<br>OMVILLE<br>BELLSHIRE<br>OM1 1HA<br> 

It should display as follows:

 101 HARRIER WAY OMVILLE BELLSHIRE OM1 1HA 

But it prints as shown below

enter image description here

UPDATE:

When I use different text instead of OMVILLE say

 101 HARRIER WAY<br>HELLO WORLD BANGALORE<br>BELLSHIRE<br>OM1 1HA<br> 

It works well. I don’t know why it doesn’t work when I give OMVILLE

enter image description here

Code:

 <?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 isStretchWithOverflow="true" pattern="" isBlankWhenNull="true"> <reportElement positionType="Float" stretchType="RelativeToTallestObject" x="117" y="141" width="297" height="105" isRemoveLineWhenBlank="true"/> <textElement markup="html"> <font size="9" isBold="false" pdfFontName="Helvetica"/> <paragraph lineSpacing="Single" tabStopWidth="60"/> </textElement> <textFieldExpression class="java.lang.String"><![CDATA[$P{address}]]></textFieldExpression> </textField> </band> </title> </jasperReport> 

I am running this code using iReport 4.0.2, and the JasperReports version is 4.

To run the above code, use all the input parameters as default values ​​and for the address parameter, which are listed below as input.

 101 HARRIER WAY<br>OMVILLE<br>BELLSHIRE<br>OM1 1HA<br> 

PS: I am creating jrxml in PDF format.

+1
source share
1 answer

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> 
+2
source

Source: https://habr.com/ru/post/1379109/


All Articles