The bird that flies 2023-04-03 11:13 采纳率: 66.7%
浏览 44

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();
  • 写回答

2条回答 默认 最新

  • isMae 2023-04-03 11:59
    关注

    参考下

    // 引入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();
    
    评论

报告相同问题?

问题事件

  • 修改了问题 4月3日
  • 修改了问题 4月3日
  • 创建了问题 4月3日