使用markup =" html"时生成为PDF文件的报告的文本对齐问题使用iReport [英] Text alignment issue with report generated as PDF file when using markup="html" using iReport

查看:139
本文介绍了使用markup =" html"时生成为PDF文件的报告的文本对齐问题使用iReport的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要在PDF中打印以下数据,

I have the following data to be printed in the PDF,

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

需要按以下方式显示,

101 HARRIER WAY
OMVILLE
BELLSHIRE
OM1  1HA

但是印刷如下:

更新:

当我在 OMVILLE 的地方使用其他文字时说

When I use other text in the place of OMVILLE say

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

效果很好。当我给 OMVILLE

代码:

<?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>

我使用 iReport 4.0.2 和我的 JasperReports 版本为4.

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

为了运行上面的代码,使用所有输入参数作为默认值,地址参数将下面的一个作为输入。

For running the above code use all the input parameters as default values and for address parameter give below one as input.

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

PS:我正在生成PDF格式的jrxml。

P.S: I am generating the jrxml in PDF format.

推荐答案

您的示例适用于此版本的 JasperReports API 4.0.1 4.1.1 ,但我遇到了与 4.0.2 版本相同的问题。

Your sample works fine with this versions of JasperReports API: 4.0.1 and 4.1.1, but I've faced the same problem as you with 4.0.2 version.

我们可以比较 JRPdfExporter 的两个版本的实现,例如 4.1.1 4.0.2 版本。

We can compare two versions of implementation of JRPdfExporter, for example the 4.1.1 and 4.0.2 versions.

正如您所见, PdfTextRenderer 对于这两个版本是不同的,例如方法 draw 改变了。此方法 draw()包含 iText 框架的rel =nofollow> ColumnText.go()方法。此方法用于在 pdf 文档中绘制文本。

As you can see the source code of PdfTextRenderer is different for this two versions, for example the method draw is changed. This method draw() contains the calling of ColumnText.go() method of iText framework. This method is using for drawing text in pdf document.


  1. 您可以升级 JasperReports 库的版本。最后一个是 5.2.0 ,您的示例使用它。如前所述,即使使用 4.1.1 ,您的示例也能正常运行

  1. You can upgrade your vestion of JasperReports library. The last one is 5.2.0 and your sample works with it. Your sample works well even with 4.1.1 as I mentioned before

您可以修复 PdfTextRenderer的源代码 class如果你不能升级 JR 库的版本。

You can fix the source code of PdfTextRenderer class if you can not upgrade the version of JR library.






关于测试你的问题



我写了一个小样本来测试你的问题。我已经使用 Maven 项目 - 在 JR 库版本之间进行简单切换。


About testing your issue

I've wrote a small sample for testing your issue. I've used the Maven project - for simple switching between JR libraries versions.

<的源代码用于测试问题的em> Java 类:

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);
} 

苗条测试 jrxml 文件是:

<?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>

这篇关于使用markup =&quot; html&quot;时生成为PDF文件的报告的文本对齐问题使用iReport的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆