JRPdfExporter导出PDF,中文不显示

jasperreports 6.17.0 JRPdfExporter导出PDF,中文不显示
怎么处理
需要注意的是jrxml文件很多。

img


关键代码如下

    response.setContentType("application/pdf");
    response.setCharacterEncoding("UTF-8");
    response.setHeader("Content-Disposition", "attachment;filename="+URLEncoder.encode(session.getAttribute("fileName")+".pdf", "UTF-8"));
    
    outputStream = response.getOutputStream();
    JRPdfExporter exporter = new JRPdfExporter();
    SimplePdfExporterConfiguration reportConfiguration = new SimplePdfExporterConfiguration();
    reportConfiguration.setCreatingBatchModeBookmarks(true);
    exporter.setConfiguration(reportConfiguration);
    exporter.setExporterInput(new SimpleExporterInput(jasperPrint));
    exporter.setExporterOutput(new SimpleOutputStreamExporterOutput(outputStream));
    exporter.exportReport();

参考下

// 引入iText字体库
FontFactory.registerDirectories();

// 设置字体
PdfExporterConfiguration configuration = new SimplePdfExporterConfiguration();
configuration.setPdfFontName("SimSun");
configuration.setFontFactory(new FontFactory());

// 创建PDF导出器并设置导出参数
JRExporter exporter = new JRPdfExporter();
SimplePdfReportConfiguration reportConfig = new SimplePdfReportConfiguration();
reportConfig.setSizePageToContent(true);
reportConfig.setForceLineBreakPolicy(false);
reportConfig.isCreatingBatchModeBookmarks();
exporter.setConfiguration(configuration);
exporter.setConfiguration(reportConfig);
exporter.setExporterInput(new SimpleExporterInput(jasperPrint));
exporter.setExporterOutput(new SimpleOutputStreamExporterOutput(outputStream));

// 执行导出操作
exporter.exportReport();
不知道你这个问题是否已经解决, 如果还没有解决的话:

如果你已经解决了该问题, 非常希望你能够分享一下解决方案, 写成博客, 将相关链接放在评论区, 以帮助更多的人 ^-^