我是贾斯珀报告的新手。我正在尝试使用字体扩展名在PDF中显示泰语字符,但由于某种原因,字符不会显示。我已经研究过这个问题并遵循官方文档(http://jasperreports.sourceforge.net/sample.reference/fonts/),但它没有用。
我使用TIBCO JasperSoft工作室进行设计,当我通过JasperSoft工作室预览设计时,一切都正确显示。但是,当我将生成的jrxml文件应用于我的Java代码时,泰语字符未显示在PDF文件中。我也试过Html文件,一切正常。
按照官方文档生成PDF,我建议导出包含TTF文件的jAR文件,jasperreports_extension.properties和fonts.xml文件。
请查看我的代码段
fontsfamily1445966397265.xml
<?xml version="1.0" encoding="UTF-8"?>
<fontFamilies>
<fontFamily name="tahoma">
<normal>fonts/tahoma/Tahoma.ttf</normal>
<bold>fonts/tahoma/tahomabd.ttf</bold>
<pdfEncoding>Identity-H</pdfEncoding>
<pdfEmbedded>true</pdfEmbedded>
<exportFonts>
<export key="xhtml">tahoma</export>
<export key="html">tahoma</export>
</exportFonts>
jasperreports_extension.properties
net.sf.jasperreports.extension.registry.factory.simple.font.families=net.sf.jasperreports.engine.fonts.SimpleFontExtensionsRegistryFactory
net.sf.jasperreports.extension.simple.font.families.ireportfamily1445966397265=fonts/fontsfamily1445966397265.xml
Java代码
JasperCompileManager.compileReportToFile(JRXML_FILE);
String printFileName = JasperFillManager.fillReportToFile(JASPER_FILE, params, conn);
JasperExportManager.exportReportToPdfFile(printFileName, PDF_FILE);
jrxml文件
<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Jaspersoft Studio version 6.1.1.final using JasperReports Library version 6.1.1 -->
<!-- 2015-10-28T01:17:50 -->
<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="receipt" pageWidth="595" pageHeight="842" whenNoDataType="AllSectionsNoDetail" columnWidth="535" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="4eedbb89-b4f6-4469-9ab6-f642a1688cf7">
<property name="template.engine" value="tabular_template"/>
<style name="Title" forecolor="#FFFFFF" fontName="tahoma" fontSize="50" isBold="false"/>
<style name="SubTitle" forecolor="#CCCCCC" fontName="tahoma" fontSize="18" isBold="false"/>
<style name="Column header" forecolor="#666666" fontName="tahoma" fontSize="14" isBold="false"/>
<style name="Detail" mode="Transparent" fontName="tahoma"/>
<style name="Row" mode="Transparent" fontName="tahoma">
<conditionalStyle>
<conditionExpression><![CDATA[$V{REPORT_COUNT}%2 == 0]]></conditionExpression>
<style mode="Opaque" backcolor="#EEEFF0"/>
</conditionalStyle>
</style>
<style name="Table">
<box>
<pen lineWidth="1.0" lineColor="#000000"/>
<topPen lineWidth="1.0" lineColor="#000000"/>
<leftPen lineWidth="1.0" lineColor="#000000"/>
<bottomPen lineWidth="1.0" lineColor="#000000"/>
<rightPen lineWidth="1.0" lineColor="#000000"/>
</box>
</style>
<style name="Table_TH" mode="Opaque" backcolor="#FFFFFF">
<box>
<pen lineWidth="0.5" lineColor="#000000"/>
<topPen lineWidth="0.5" lineColor="#000000"/>
<leftPen lineWidth="0.5" lineColor="#000000"/>
<bottomPen lineWidth="0.5" lineColor="#000000"/>
<rightPen lineWidth="0.5" lineColor="#000000"/>
</box>
</style>
<style name="Table_CH" mode="Opaque" backcolor="#CACED0">
<box>
<pen lineWidth="0.5" lineColor="#000000"/>
<topPen lineWidth="0.5" lineColor="#000000"/>
<leftPen lineWidth="0.5" lineColor="#000000"/>
<bottomPen lineWidth="0.5" lineColor="#000000"/>
<rightPen lineWidth="0.5" lineColor="#000000"/>
</box>
</style>
<style name="Table_TD" mode="Opaque" backcolor="#FFFFFF">
<box>
<pen lineWidth="0.5" lineColor="#000000"/>
<topPen lineWidth="0.5" lineColor="#000000"/>
<leftPen lineWidth="0.5" lineColor="#000000"/>
<bottomPen lineWidth="0.5" lineColor="#000000"/>
<rightPen lineWidth="0.5" lineColor="#000000"/>
</box>
<conditionalStyle>
<conditionExpression><![CDATA[$V{REPORT_COUNT}%2 == 0]]></conditionExpression>
<style backcolor="#D8D8D8"/>
</conditionalStyle>
</style>
<subDataset name="tableDataset" uuid="6590503c-ab84-4f89-80d9-38ac71dd1404">
<property name="com.jaspersoft.studio.data.defaultdataadapter" value="New Data Adapter "/>
<property name="com.jaspersoft.studio.data.sql.tables" value=""/>
<parameter name="customer_id" class="java.lang.Long"/>
<queryString>
<![CDATA[SELECT l.name, lbd.buy_type, lbd.buy_price, (lbd.buy_price - down_payment) AS debt FROM land l INNER JOIN land_buy_detail lbd ON l.id = lbd.land_id WHERE lbd.customer_id = $P{customer_id}]]>
</queryString>
<field name="name" class="java.lang.String"/>
<field name="buy_type" class="java.lang.String"/>
<field name="buy_price" class="java.lang.Float"/>
<field name="debt" class="java.lang.Float"/>
</subDataset>
<parameter name="customer_id" class="java.lang.Long">
<parameterDescription><![CDATA[]]></parameterDescription>
<defaultValueExpression><![CDATA[$P{customer_id}]]></defaultValueExpression>
</parameter>
<queryString>
<![CDATA[SELECT firstname, lastname, address, tel FROM customer WHERE id = $P{customer_id}]]>
</queryString>
<field name="firstname" class="java.lang.String"/>
<field name="lastname" class="java.lang.String"/>
<field name="address" class="java.lang.String"/>
<field name="tel" class="java.lang.String"/>
<title>
<band height="357" splitType="Stretch">
<staticText>
<reportElement x="0" y="90" width="84" height="25" uuid="57aed2b1-4f4e-40a3-a6ad-54dae8dd4c5a">
<property name="local_mesure_unitheight" value="pixel"/>
<property name="com.jaspersoft.studio.unit.height" value="px"/>
</reportElement>
<textElement>
<font size="16" isBold="true"/>
</textElement>
<text><![CDATA[Bill to:]]></text>
</staticText>
<line>
<reportElement x="0" y="80" width="556" height="1" uuid="806ce5df-1219-4876-ae0c-ca7405b1f246">
<property name="local_mesure_unitheight" value="pixel"/>
<property name="com.jaspersoft.studio.unit.height" value="px"/>
</reportElement>
</line>
<staticText>
<reportElement x="415" y="10" width="50" height="20" uuid="0f86baff-6386-4f3f-b3fe-2388707babe8"/>
<box rightPadding="4"/>
<textElement textAlignment="Right"/>
<text><![CDATA[Date:]]></text>
</staticText>
<textField pattern="EEEEE dd MMMMM yyyy">
<reportElement x="465" y="10" width="84" height="20" uuid="bb10dbe1-0a4f-4722-9953-c163b63cf979"/>
<textFieldExpression><![CDATA[new java.util.Date()]]></textFieldExpression>
</textField>
<image hAlign="Center">
<reportElement x="0" y="0" width="65" height="60" uuid="94883631-a913-43e2-b182-ab8d77d0181e"/>
<imageExpression><![CDATA["invoice_logo.png"]]></imageExpression>
</image>
<textField pattern="EEEEE dd MMMMM yyyy">
<reportElement x="465" y="30" width="84" height="20" uuid="3836ce65-eca3-4cad-a6de-b1818def0a2b"/>
<textFieldExpression><![CDATA["INV0001"]]></textFieldExpression>
</textField>
<staticText>
<reportElement x="415" y="30" width="50" height="20" uuid="0b3f9342-da78-4cfa-9fc5-2301c4749678"/>
<box rightPadding="4"/>
<textElement textAlignment="Right"/>
<text><![CDATA[Invoice:]]></text>
</staticText>
<staticText>
<reportElement x="95" y="0" width="205" height="25" uuid="e622555d-198b-4ccd-a4a1-c59c53304058">
<property name="local_mesure_unitheight" value="pixel"/>
<property name="com.jaspersoft.studio.unit.height" value="px"/>
</reportElement>
<textElement>
<font size="19" isBold="true"/>
</textElement>
<text><![CDATA[BP Property]]></text>
</staticText>
<staticText>
<reportElement x="95" y="55" width="205" height="15" uuid="b8cc42fd-b569-497d-834d-7e854040ad18"/>
<textElement>
<font fontName="tahoma"/>
</textElement>
<text><![CDATA[08-19595-240]]></text>
</staticText>
<staticText>
<reportElement x="95" y="25" width="205" height="15" uuid="c226e44d-3bb5-4145-b0b3-903bf1d79fde"/>
<textElement markup="none">
<font fontName="tahoma" size="11" isBold="false"/>
</textElement>
<text><![CDATA[1174 ถ. เพชรเกษม อ. หาดใหญ่]]></text>
</staticText>
<staticText>
<reportElement positionType="FixRelativeToBottom" x="95" y="40" width="205" height="15" uuid="b96f7183-44f8-43ad-ba60-43d8fbf50b6e"/>
<textElement>
<font fontName="tahoma"/>
</textElement>
<text><![CDATA[ต. หาดใหญ่ จ. สงขลา 90110]]></text>
</staticText>
<textField>
<reportElement x="0" y="115" width="120" height="15" uuid="0e5185a4-3292-4051-927f-7e07f549bceb"/>
<textFieldExpression><![CDATA[new String($F{firstname} + " " + $F{lastname})]]></textFieldExpression>
</textField>
<textField>
<reportElement x="0" y="130" width="120" height="15" uuid="0925d7fe-e543-4225-b44e-ff1828d6cb8a"/>
<textFieldExpression><![CDATA[$F{address}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="0" y="145" width="120" height="15" uuid="199db39e-5210-4d3a-a0c5-baf4543d9d49"/>
<textFieldExpression><![CDATA[$F{tel}]]></textFieldExpression>
</textField>
<componentElement>
<reportElement x="0" y="166" width="555" height="130" uuid="b8e9c2ed-feb3-408c-b9be-6aebbeb6af52"/>
<jr:table xmlns:jr="http://jasperreports.sourceforge.net/jasperreports/components" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports/components http://jasperreports.sourceforge.net/xsd/components.xsd">
<datasetRun subDataset="tableDataset" uuid="6ea978fd-ffe0-40bb-84a7-f09b1f220cfa">
<datasetParameter name="customer_id">
<datasetParameterExpression><![CDATA[$P{customer_id}]]></datasetParameterExpression>
</datasetParameter>
<connectionExpression><![CDATA[$P{REPORT_CONNECTION}]]></connectionExpression>
</datasetRun>
<jr:column width="190" uuid="06d1364f-8060-496c-ac0c-b44946e09dd0">
<jr:columnHeader style="Table_CH" height="30">
<staticText>
<reportElement key="" style="Column header" x="0" y="0" width="190" height="30" forecolor="#000000" uuid="93321529-b12d-4528-8316-4e6e94a6c476">
<property name="com.jaspersoft.studio.unit.x" value="pixel"/>
</reportElement>
<box leftPadding="2"/>
<textElement textAlignment="Center" verticalAlignment="Middle">
<font fontName="tahoma" size="12" isBold="true"/>
</textElement>
<text><![CDATA[รายการ]]></text>
</staticText>
</jr:columnHeader>
<jr:detailCell style="Table_TD" height="30">
<textField>
<reportElement style="Detail" x="0" y="0" width="190" height="30" uuid="4be9692f-e0bf-4a89-9f21-b579d46c9adf">
<property name="com.jaspersoft.studio.unit.x" value="pixel"/>
</reportElement>
<box leftPadding="2"/>
<textElement textAlignment="Left" verticalAlignment="Middle">
<font fontName="tahoma" size="12"/>
</textElement>
<textFieldExpression><![CDATA[" " + $F{name}]]></textFieldExpression>
</textField>
</jr:detailCell>
</jr:column>
<jr:column width="90" uuid="25357c6d-7a1a-4bcb-ac60-8d18805b681c">
<jr:columnHeader style="Table_CH" height="30">
<staticText>
<reportElement x="0" y="0" width="90" height="30" forecolor="#000000" uuid="c8f288aa-8d2e-48ce-8ee7-d710740d7b52"/>
<box leftPadding="2"/>
<textElement textAlignment="Center" verticalAlignment="Middle">
<font fontName="tahoma" size="12" isBold="true"/>
</textElement>
<text><![CDATA[ประเภท]]></text>
</staticText>
</jr:columnHeader>
<jr:detailCell style="Table_TD" height="30">
<textField>
<reportElement style="Detail" x="0" y="0" width="90" height="30" uuid="6735552d-0796-499f-af74-e308260bc5e0"/>
<box leftPadding="2"/>
<textElement textAlignment="Left" verticalAlignment="Middle">
<font fontName="tahoma" size="12"/>
</textElement>
<textFieldExpression><![CDATA[($F{buy_type}.equals("C")) ? " สด" : " ผ่อน"]]></textFieldExpression>
</textField>
</jr:detailCell>
</jr:column>
<jr:column width="120" uuid="18cfa391-26d8-4a47-8e88-a7d1bef16d74">
<jr:columnHeader style="Table_CH" height="30">
<staticText>
<reportElement key="" style="Column header" x="0" y="0" width="120" height="30" forecolor="#000000" uuid="fc75656e-008d-47b4-ab25-2cdb62acb876"/>
<box leftPadding="2"/>
<textElement textAlignment="Center" verticalAlignment="Middle">
<font fontName="tahoma" size="12" isBold="true"/>
</textElement>
<text><![CDATA[ราคาซื้อ]]></text>
</staticText>
</jr:columnHeader>
<jr:detailCell style="Table_TD" height="30">
<textField>
<reportElement style="Detail" x="0" y="0" width="120" height="30" uuid="db5ac821-df67-42ec-8f12-c3cbce27a8fd"/>
<box leftPadding="2"/>
<textElement textAlignment="Left" verticalAlignment="Middle">
<font fontName="tahoma" size="12"/>
</textElement>
<textFieldExpression><![CDATA[" " + $F{buy_price}]]></textFieldExpression>
</textField>
</jr:detailCell>
</jr:column>
<jr:column width="155" uuid="c192f0f1-d7f3-4362-8149-f9d592cdac30">
<jr:columnHeader style="Table_CH" height="30">
<staticText>
<reportElement key="" style="Column header" stretchType="RelativeToTallestObject" x="0" y="0" width="155" height="30" forecolor="#000000" uuid="2c3771ca-3b46-4bae-837b-88fac22baff7"/>
<box leftPadding="2"/>
<textElement textAlignment="Center" verticalAlignment="Middle">
<font fontName="tahoma" size="12" isBold="false"/>
</textElement>
<text><![CDATA[ยอดคงค้าง]]></text>
</staticText>
</jr:columnHeader>
<jr:detailCell style="Table_TD" height="30">
<textField pattern="#,###.##">
<reportElement style="Detail" x="10" y="0" width="145" height="30" uuid="94659f20-5913-48a2-b64c-683d0584936c"/>
<box leftPadding="2"/>
<textElement textAlignment="Left" verticalAlignment="Middle">
<font size="12"/>
</textElement>
<textFieldExpression><![CDATA[$F{debt}]]></textFieldExpression>
</textField>
</jr:detailCell>
</jr:column>
</jr:table>
</componentElement>
<staticText>
<reportElement positionType="Float" mode="Opaque" x="0" y="290" width="556" height="30" backcolor="#E6E8E9" uuid="36aa233d-4305-48e6-974a-1bbf89bb3c8f"/>
<textElement textAlignment="Center" verticalAlignment="Middle">
<font fontName="tahoma" size="9" isItalic="true"/>
</textElement>
<text><![CDATA[THANKYOU FOR YOUR BUSINESS]]></text>
</staticText>
</band>
</title>
<summary>
<band height="293" splitType="Stretch">
<property name="local_mesure_unitheight" value="pixel"/>
</band>
</summary>
我确定JAR文件位于我的Maven类路径中。
我正在使用Jaspersoft Studio版本6.1.1.final使用JasperReports Library版本6.1.1。
答案 0 :(得分:1)
我解决了这个问题。我只是忘了将JASPER_FILE变量指向正确的文件。这种用于显示国际字符的解决方案已经有效:)