jasperreports 6.17.0 JRPdfExporter导出PDF,中文不显示
怎么处理
需要注意的是jrxml文件很多。
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();
不知道你这个问题是否已经解决, 如果还没有解决的话: