我和JasperReports合作了几个星期。我以HTML,DOCX和PDF格式导出报告。
DOCX和HTML报告看起来不错,但在PDF格式中,textElement中的文本有时会被截断。
也许有人可以帮助我?
这是textElement的jrxml代码:
<detail>
<band height="29" splitType="Stretch">
<property name="com.jaspersoft.studio.layout" value="com.jaspersoft.studio.editor.layout.FreeLayout"/>
<textField isStretchWithOverflow="true" isBlankWhenNull="true">
<reportElement positionType="Float" stretchType="RelativeToTallestObject" x="260" y="0" width="284" height="29" isRemoveLineWhenBlank="true" isPrintWhenDetailOverflows="true" uuid="602856c9-7bf6-481d-a9f9-449498ff5168">
<property name="net.sf.jasperreports.print.keep.full.text" value="true"/>
</reportElement>
<textElement>
<font fontName="Arial" size="10" isBold="true"/>
<paragraph lineSpacing="Single" spacingBefore="3" spacingAfter="3"/>
</textElement>
<textFieldExpression><![CDATA[$F{TEXT}]]></textFieldExpression>
</textField>
<textField isStretchWithOverflow="true" isBlankWhenNull="true">
<reportElement positionType="Float" stretchType="RelativeToTallestObject" x="110" y="0" width="140" height="18" isRemoveLineWhenBlank="true" uuid="4c12bb30-f160-42ba-a6a1-60f0f9832732">
<property name="com.jaspersoft.studio.unit.y" value="pixel"/>
</reportElement>
<textElement>
<font fontName="Arial" size="10" isBold="false"/>
<paragraph spacingBefore="3" spacingAfter="3"/>
</textElement>
<textFieldExpression><![CDATA[$F{NAME}]]></textFieldExpression>
</textField>
<textField isStretchWithOverflow="true" isBlankWhenNull="true">
<reportElement positionType="Float" stretchType="RelativeToTallestObject" x="60" y="0" width="50" height="18" isRemoveLineWhenBlank="true" uuid="f3242a8a-555e-451a-84c6-9cb1e9e5654b">
<property name="com.jaspersoft.studio.unit.x" value="pixel"/>
<property name="com.jaspersoft.studio.unit.y" value="pixel"/>
</reportElement>
<textElement>
<font fontName="Arial" size="10" isBold="false"/>
<paragraph spacingBefore="3" spacingAfter="3"/>
</textElement>
<textFieldExpression><![CDATA["[".concat(String.format("%03d", $F{BT})).concat("]")]]></textFieldExpression>
</textField>
</band>
</detail>
我还添加了字体和jasperreports_extension.properties 这是jasperreports_extension.properties:
net.sf.jasperreports.export.pdf.force.linebreak.policy=true
net.sf.jasperreports.print.keep.full.text=true
net.sf.jasperreports.default.pdf.encoding=Identity-H
net.sf.jasperreports.extension.registry.factory.fonts=net.sf.jasperreports.engine.fonts.SimpleFontExtensionsRegistryFactory
net.sf.jasperreports.extension.simple.font.families.myfamily=/fonts/myfamily.xml
属性
net.sf.jasperreports.export.pdf.force.linebreak.policy=true
对我的pdf文件没有影响。
这里是我创建PDF的java类的代码(注意这不是完整的代码):
JasperPrint jasperPrint = new JasperPrint();
this.getDataForReport();
JRResultSetDataSource rsDataSource = new JRResultSetDataSource(this.resultSetReport);
JRDataSource jrData = rsDataSource;
HashMap<String, Object> param = new HashMap<String, Object>();
JasperReport jasperReportMain = JasperCompileManager.compileReport(ReportsConfiguration
.getTemplatePath() + "report.jrxml");
jasperPrint = JasperFillManager.fillReport(jasperReportMain, param, jrData);
JRPdfExporter exporterPDF = new JRPdfExporter();
exporterPDF.setExporterInput(new SimpleExporterInput(jasperPrint));
File exportReportFilePdf = new File(fileNamePdf);
exporterPDF.setExporterOutput(new SimpleOutputStreamExporterOutput(exportReportFilePdf));
exporterPDF.exportReport();