2

我有一个表格iReport可以正确生成 PDF:

<componentElement>
    <reportElement key="server vendor table" style="table" x="272" y="437" width="150" height="115"/>
    <jr:table>
        <jr:column width="50">
            <jr:columnHeader style="table_CH" height="15" rowSpan="1">
                <staticText>
                    <reportElement x="5" y="0" width="45" height="15"/>
                    <textElement/>
                    <text><![CDATA[Server Vendor]]></text>
                </staticText>
            </jr:columnHeader>
            <jr:detailCell style="table_TD" height="18" rowSpan="1">
                <textField>
                    <reportElement x="5" y="0" width="45" height="15"/>
                    <textElement/>
                    <textFieldExpression><![CDATA[$F{vendor}]]></textFieldExpression>
                </textField>
            </jr:detailCell>
        </jr:column>
        <jr:column width="50">
            <jr:columnHeader style="table_CH" height="15" rowSpan="1">
                <staticText>
                    <reportElement x="5" y="0" width="45" height="15"/>
                    <textElement/>
                    <text><![CDATA[# Hosts]]></text>
                </staticText>
            </jr:columnHeader>
            <jr:detailCell style="table_TD" height="18" rowSpan="1">
                <textField>
                    <reportElement x="5" y="0" width="45" height="15"/>
                    <textElement/>
                    <textFieldExpression><![CDATA[$F{count}]]></textFieldExpression>
                </textField>
            </jr:detailCell>
        </jr:column>
        <jr:column width="50">
            <jr:columnHeader style="table_CH" height="15" rowSpan="1">
                <staticText>
                    <reportElement x="5" y="0" width="45" height="15"/>
                    <textElement/>
                    <text><![CDATA[Host %]]></text>
                </staticText>
            </jr:columnHeader>
            <jr:detailCell style="table_TD" height="18" rowSpan="1">
                <textField>
                    <reportElement x="5" y="0" width="45" height="15"/>
                    <textElement/>
                    <textFieldExpression><![CDATA[$F{pc}]]></textFieldExpression>
                </textField>
            </jr:detailCell>
        </jr:column>
    </jr:table>
</componentElement>

从 生成报告时iReport,正确生成了 PDF,结果为: 使用 iReport 生成的正确结果

但是当使用 Java 生成时,第一列中“HP”的文本条目被分成多行: 使用 Java 代码生成的错误结果

请注意,只有“HP”文本被拆分 - 带有空格的较长文本(例如“Dell inc.”)不会被拆分。

我猜我需要设置一些属性,但我看不出我需要设置哪个属性。

Class.forName("org.postgresql.Driver");
Connection conn = DriverManager.getConnection("jdbc:postgresql://localhost:5432/hardwaredata","???","???");       
InputStream input = new FileInputStream(new File("/reports/hardware_report.jrxml"));
JasperDesign design = JRXmlLoader.load(input);
input.close();
Map<String, Object> param_map = new HashMap<String, Object>();
JasperReport jReport = JasperCompileManager.compileReport(design);
JasperPrint jPrint = JasperFillManager.fillReport(jReport, param_map, conn);
String path = application.getRealPath("/") + "/"+"static_report.pdf";
JasperExportManager.exportReportToPdfFile(jPrint, path);
4

2 回答 2

0

在垂直对齐的文本的属性中,选中标题为“溢出溢出”的字段

于 2012-04-11T14:23:22.463 回答
0

我以前见过这个。我不记得找到真正的原因。同样奇怪(但很高兴)我发现像“HP”这样的字符串不会表现出这种行为。

尝试更改您的文本字段以显示以下内容:$F{Vendor} + " "

一定要记录一个错误!但这可能足以解决眼前的问题。

于 2012-04-11T20:37:06.463 回答