简体   繁体   English

JasperReports:导出为PDF后,UTF-8中的某些符号丢失了

[英]JasperReports: Some symbols from UTF-8 are lost after exporting to PDF

I have a report that is exported to XLSX and PDF. 我有一个导出到XLSX和PDF的报告。 The code of both exporters is pretty similar at the same time encoding is lost during PDF export. 两个导出器的代码非常相似,同时PDF导出过程中丢失了编码。

For instance, the following symbols are simply skipped in the end result: "Č", "ć". 例如,在最终结果中仅跳过以下符号:“Č”,“ć”。 At the same time "ü", "ß" are printed correctly. 同时正确打印“ü”,“ß”。

In XLSx exporter ( working part ) I use pretty simple code: 在XLSx导出器( 工作部分 )中,我使用了非常简单的代码:

try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) {
    JRXlsxExporter xlsExporter = new JRXlsxExporter();
    xlsExporter.setExporterInput(new SimpleExporterInput(jasperPrint));
    xlsExporter.setExporterOutput(new SimpleOutputStreamExporterOutput(outputStream));
    xlsExporter.exportReport();
    return outputStream.toByteArray();
}

In case of PDF I use pretty the same code ( doesn't work ): 在PDF的情况下,我使用几乎相同的代码( 不起作用 ):

try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) {
    JRPdfExporter exporter = new JRPdfExporter();
    exporter.setExporterInput(new SimpleExporterInput(jasperPrint));
    exporter.setExporterOutput(new SimpleOutputStreamExporterOutput(outputStream));
    exporter.exportReport();
    return outputStream.toByteArray();
}

But it doesn't work. 但这是行不通的。 In both cases I pass the same instance of jasperPrint . 在两种情况下,我都传递相同的jasperPrint实例。

I tried playing around with PdfExporterConfiguration to set up some parameters, but unfortunately haven't found any encoding related configuration. 我尝试使用PdfExporterConfiguration来设置一些参数,但是很遗憾,没有找到任何与编码相关的配置。

Q: What might cause the problem? 问:什么可能导致问题? Any idea how to fix it? 知道如何解决吗?

My suspision is that the problem comes from the fonts you are using. 我的怀疑是问题出在您使用的字体上。 Are you sure both XLSX and PDF support the font you have set in your report? 您确定XLSX和PDF都支持您在报告中设置的字体吗? In the generated PDF you can check the used font by right-clicking and choosing document properties - there is a tab with fonts. 在生成的PDF中,您可以通过右键单击并选择文档属性来检查使用的字体-有一个带有字体的选项卡。 Does the font in PDF support those symbols? PDF中的字体是否支持这些符号?

If I remember correctly sometimes when exporting to PDF the exporter will use some different font (if the one you wanted is not found/supported or something). 如果我没有记错的话,有时导出到PDF时,导出器将使用某种不同的字体(如果找不到/不支持您想要的字体)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM