gpt4 book ai didi

java - 如何在 Jasper 报告导出的 PDF 中正确显示越南语?

转载 作者:行者123 更新时间:2023-11-30 01:48:00 26 4
gpt4 key购买 nike

我正在使用这些依赖项

implementation ('net.sf.jasperreports:jasperreports:6.9.0')
implementation ('net.sf.jasperreports:jasperreports-fonts:6.9.0')
implementation ('net.sf.jasperreports:jasperreports-functions:6.9.0')
implementation ('net.sf.jasperreports:jasperreports-metadata:6.9.0')
implementation ('net.sf.jasperreports:jasperreports-fonts:6.9.0')
implementation ('net.sf.jasperreports:jasperreports-annotation-processors:6.9.0')
implementation ('net.sf.jasperreports:jasperreports-chart-themes:6.9.0')
implementation ('net.sf.jasperreports:jasperreports-chart-customizers:6.9.0')
implementation ('net.sf.jasperreports:jasperreports-custom-visualization:6.9.0')
compile 'com.lowagie:itext:2.1.7.js5'

带有 Eclipse 2019.6 的 Jasper 报告。越南语字符显示错误

Java代码

@RequestMapping(value = "/ca_audit/minute_pdf", method = RequestMethod.GET)
public void generatePDFCashAuditMinute() throws JRException {
JasperReport jasperReport = JasperCompileManager.compileReport("D:/vy/template.jrxml");
Map<String, Object> parameters = new HashMap<>();
parameters.put("p1", "Example joint stock company"); // Tên tổ chức
parameters.put("p2", "EXKK002"); // Số biên bản
parameters.put("p3", 26); // Ngày
JRDataSource jrDataSource = new JREmptyDataSource();
JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, parameters, jrDataSource);
JasperExportManager.exportReportToPdfFile(jasperPrint, "D:/foo/out.pdf");
}

文件*.jrxml的内容

<?xml version="1.0" encoding="UTF-8"?>
<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="bien_ban_kiem_ke_quy_a4" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="7098c966-5c92-43e3-a729-b3d486fc858b">
<parameter name="p1" class="java.lang.String"/>
<parameter name="p2" class="java.lang.String"/>
<parameter name="p3" class="java.lang.Integer"/>
<queryString>
<![CDATA[select 1 as id]]>
</queryString>
<field name="id" class="java.lang.Integer"/>
<title>
<band height="84" splitType="Stretch">
<textField>
<reportElement x="14" y="6" width="100" height="30" uuid="2106c35d-3d5e-4203-950a-54a87b6952ea"/>
<textElement>
<font fontName="Arial"/>
</textElement>
<textFieldExpression><![CDATA[$P{p1}]]></textFieldExpression>
</textField>
<staticText>
<reportElement x="376" y="23" width="64" height="16" uuid="77d41a67-82d2-46d0-9a3e-5327ae3b450b"/>
<text><![CDATA[Số biên bản:]]></text>
</staticText>
<textField>
<reportElement x="440" y="23" width="50" height="16" uuid="a505da46-48af-4dcb-84bc-f9d27697919d"/>
<textFieldExpression><![CDATA[$P{p2}]]></textFieldExpression>
</textField>
<staticText>
<reportElement x="260" y="47" width="34" height="13" uuid="541c25ed-4b29-4cc4-a19d-05f295ae0340"/>
<text><![CDATA[ngày]]></text>
</staticText>
<textField>
<reportElement x="290" y="47" width="40" height="13" uuid="72e64426-d702-4694-bc25-81a2f3e43f82"/>
<textFieldExpression><![CDATA[$P{p3}]]></textFieldExpression>
</textField>
</band>
</title>
</jasperReport>

我在类路径中创建文件jasperreports.properties enter image description here

在 Eclipse IDE 中(带有 Jaspersoft 模块) enter image description here

如何解决?

最佳答案

这是一个字体问题。不是PDF编码问题。也许尝试使用Arial Unicode MS

在标签内添加以下内容

<font fontName="Arial Unicode MS" size="11" pdfFontName="Arial Unicode MS" pdfEncoding="Identity-H"/> 

还要确保 Arial 字体扩展 jar 在类路径中。在互联网上搜索 arial 字体扩展 jar。

关于java - 如何在 Jasper 报告导出的 PDF 中正确显示越南语?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57224644/

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