gpt4 book ai didi

java - Jasper 报告生成错误

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:03:34 30 4
gpt4 key购买 nike

我在 Jaspersoft Studio 5.1.0 上设计了一个 JRXML,能够在 Eclipse 和 Windows 机器上生成 CSV 格式的报告。当我将 java 代码导出到 Unix 服务器时,出现以下错误。

Unix 服务器的 Java 版本:“1.7.0.08”

Caused by: java.lang.ExceptionInInitializerError
at net.sf.jasperreports.engine.fill.JRBaseFiller.<init>(JRBaseFiller.java:121)
at net.sf.jasperreports.engine.fill.JRVerticalFiller.<init>(JRVerticalFiller.java:88)
at net.sf.jasperreports.engine.fill.JRVerticalFiller.<init>(JRVerticalFiller.java:103)
at net.sf.jasperreports.engine.fill.JRVerticalFiller.<init>(JRVerticalFiller.java:61)
at net.sf.jasperreports.engine.fill.JRFiller.createFiller(JRFiller.java:179)
at net.sf.jasperreports.engine.fill.JRFiller.fill(JRFiller.java:148)
at net.sf.jasperreports.engine.JasperFillManager.fill(JasperFillManager.java:464)
at net.sf.jasperreports.engine.JasperFillManager.fillReport(JasperFillManager.java:861)
at com.infy.ui.mig.compare.MigrationUXAndONSCompare.GenerateReport(MigrationUXAndONSCompare.java:518)
... 2 more
Caused by: net.sf.jasperreports.engine.JRRuntimeException: java.io.IOException: Problem reading font data.
at net.sf.jasperreports.engine.fonts.SimpleFontFace.setTtf(SimpleFontFace.java:182)
at net.sf.jasperreports.engine.fonts.SimpleFontExtensionHelper.parseFontFace(SimpleFontExtensionHelper.java:364)
at net.sf.jasperreports.engine.fonts.SimpleFontExtensionHelper.parseFontFamily(SimpleFontExtensionHelper.java:290)
at net.sf.jasperreports.engine.fonts.SimpleFontExtensionHelper.parseFontFamilies(SimpleFontExtensionHelper.java:254)
at net.sf.jasperreports.engine.fonts.SimpleFontExtensionHelper.loadFontFamilies(SimpleFontExtensionHelper.java:215)
at net.sf.jasperreports.engine.fonts.SimpleFontExtensionHelper.loadFontFamilies(SimpleFontExtensionHelper.java:184)
at net.sf.jasperreports.engine.fonts.FontExtensionsRegistry.getExtensions(FontExtensionsRegistry.java:56)
at net.sf.jasperreports.extensions.DefaultExtensionsRegistry.getExtensions(DefaultExtensionsRegistry.java:110)
at net.sf.jasperreports.engine.util.JRStyledTextParser.<clinit>(JRStyledTextParser.java:83)
... 11 more
Caused by: java.io.IOException: Problem reading font data.
at java.awt.Font.createFont0(Font.java:999)
at java.awt.Font.createFont(Font.java:876)
at net.sf.jasperreports.engine.fonts.SimpleFontFace.setTtf(SimpleFontFace.java:174)
... 19 more

Java 代码:

JasperPrint jasperPrint;
JasperReport jasperReport;
HashMap jasperParams = new HashMap();

InputStream input = new FileInputStream(jrxmlFile);
JasperDesign design = JRXmlLoader.load(input);
jasperReport = JasperCompileManager.compileReport(design);
jasperReport.isIgnorePagination();
Document document = JRXmlUtils.parse(JRLoader.getLocationInputStream(writeFileDir));

jasperParams.put(jasperReport.isIgnorePagination(), Boolean.TRUE);
jasperParams.put(JRXPathQueryExecuterFactory.PARAMETER_XML_DATA_DOCUMENT, document);
jasperPrint = JasperFillManager.fillReport(jasperReport, jasperParams);

JRCsvExporter exporter = new JRCsvExporter();
exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
exporter.setParameter(JRExporterParameter.OUTPUT_FILE_NAME, csvReportName);
exporter.exportReport();

JRXML 文件:

<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Jaspersoft Studio version last-->
<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="HCOTA_RTACOF" language="groovy" pageWidth="3500" pageHeight="4000" columnWidth="3460" columnSpacing="37" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" isIgnorePagination="true" uuid="b857e321-5d0f-4309-a5f5-950316db1f9d">
<property name="com.jaspersoft.studio.unit." value="pixel"/>
<property name="com.jaspersoft.studio.data.defaultdataadapter" value="XmlDataSource_HRDM_ARD"/>
<subDataset name="Dataset1" uuid="62525010-7a4a-47a7-b029-c7502b171ae9">
<queryString>
<![CDATA[]]>
</queryString>
<field name="field_name" class="java.lang.String">
<fieldDescription><![CDATA[@name]]></fieldDescription>
</field>
<field name="group-name-ons" class="java.lang.String">
<fieldDescription><![CDATA[field-type[@type = "ons"]/group-name]]></fieldDescription>
</field>
<field name="page-name-ons" class="java.lang.String">
<fieldDescription><![CDATA[field-type[@type = "ons"]/page-name]]></fieldDescription>
</field>
</subDataset>
<queryString language="XPath">
<![CDATA[/menu-compare/field-details/fields]]>
</queryString>
<field name="field_exists" class="java.lang.String">
<fieldDescription><![CDATA[@existence]]></fieldDescription>
</field>
<background>
<band splitType="Stretch"/>
</background>
<title>
<band height="79" splitType="Stretch"/>
</title>
<pageHeader>
<band height="82" splitType="Stretch"/>
</pageHeader>
<columnHeader>
<band height="120" splitType="Immediate">
<printWhenExpression><![CDATA[$V{PAGE_NUMBER}==1]]></printWhenExpression>
<textField>
<reportElement uuid="78cd7b95-378a-47a7-a2e6-635677759067" x="10" y="60" width="70" height="30" backcolor="#FFFFFF"/>
<textElement>
<font isBold="true"/>
</textElement>
<textFieldExpression><![CDATA["Map Type"]]></textFieldExpression>
</textField>
<textField isStretchWithOverflow="true">
<reportElement uuid="a11ecb4a-06f1-400f-953f-e39edbcf3d9f" isPrintRepeatedValues="false" x="80" y="60" width="70" height="30"/>
<textElement>
<font isBold="true"/>
</textElement>
<textFieldExpression><![CDATA["Back End Field"]]></textFieldExpression>
</textField>
<textField>
<reportElement uuid="40a166e8-1aa0-45e8-a10c-ecf61f6b2f5a" x="150" y="60" width="70" height="30"/>
<textElement>
<font isBold="true" pdfFontName="Helvetica-Bold"/>
</textElement>
<textFieldExpression><![CDATA["Group Name"]]></textFieldExpression>
</textField>
<textField>
<reportElement uuid="c19e0438-7cf9-499e-80d4-7e2f8caaa54b" x="220" y="60" width="70" height="30"/>
<textElement>
<font isBold="true"/>
</textElement>
<textFieldExpression><![CDATA["Page Name"]]></textFieldExpression>
</textField>
</band>
</columnHeader>
<detail>
<band height="125" splitType="Stretch">
<componentElement>
<reportElement uuid="f80aa2dd-1bdd-41fe-82f2-59b4e56d4b28" x="10" y="40" width="1760" height="60"/>
<jr:list xmlns:jr="http://jasperreports.sourceforge.net/jasperreports/components" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports/components http://jasperreports.sourceforge.net/xsd/components.xsd" printOrder="Horizontal">
<datasetRun subDataset="Dataset1" uuid="c1fe8920-0512-41bc-9f79-8fcbc61ac067">
<dataSourceExpression><![CDATA[$P{REPORT_DATA_SOURCE}.subDataSource("/fields/field")]]></dataSourceExpression>
</datasetRun>
<jr:listContents height="125" width="1760">
<textField isStretchWithOverflow="true" isBlankWhenNull="true">
<reportElement uuid="8d3ab036-d155-4f07-9345-dd37dd3f7101" x="70" y="15" width="70" height="30"/>
<textElement/>
<textFieldExpression><![CDATA[$F{field_name}]]></textFieldExpression>
</textField>
<textField isStretchWithOverflow="true" isBlankWhenNull="true">
<reportElement uuid="575757aa-2b24-446e-aa79-ea0c5eb02049" x="140" y="15" width="70" height="30"/>
<textElement/>
<textFieldExpression><![CDATA[$F{group-name-ons}]]></textFieldExpression>
</textField>
<textField isStretchWithOverflow="true" isBlankWhenNull="true">
<reportElement uuid="09512867-0754-4544-991f-8dd4ffc7d8c6" x="210" y="15" width="70" height="30"/>
<textElement/>
<textFieldExpression><![CDATA[$F{page-name-ons}]]></textFieldExpression>
</textField>
</jr:listContents>
</jr:list>
</componentElement>
<textField isStretchWithOverflow="true" isBlankWhenNull="true">
<reportElement uuid="fd3813e4-e26d-48ec-8519-c2c25780f48c" x="10" y="55" width="70" height="30"/>
<textElement>
<font isBold="true"/>
</textElement>
<textFieldExpression><![CDATA[$F{field_exists}]]></textFieldExpression>
</textField>
</band>
</detail>
<columnFooter>
<band height="45" splitType="Stretch"/>
</columnFooter>
<pageFooter>
<band height="54" splitType="Stretch"/>
</pageFooter>
<summary>
<band height="42" splitType="Stretch"/>
</summary>
</jasperReport>

最佳答案

我认为 pdfFontName="Helvetica-Bold" 是导致问题的原因。这里有两件事需要考虑。

  1. 当您导出报告并希望在其中显示 Helvetica-Bold 时,您将为它创建字体扩展,除非您的 JVM 已经使用它作为 Helvetica-Bold。
  2. 您必须在 jrxml 文件中创建自定义样式并在那里使用字体,并在使用字体扩展名的情况下将样式应用于元素。

希望对你有帮助。

关于java - Jasper 报告生成错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25239317/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com