我有一个表格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,结果为:
但是当使用 Java 生成时,第一列中“HP”的文本条目被分成多行:
请注意,只有“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);