【问题标题】:Export PDF with jasper report使用碧玉报告导出 PDF
【发布时间】:2021-09-15 08:46:26
【问题描述】:

我正在尝试在 Spring Boot 项目中使用 jasper 报告导出 PDF 文件,这是我的控制器:

所以使用这种方法,pdf文件在我的项目中本地导出,我想对其进行更改,以便可以将其导出到我电脑上的指定路径中。

【问题讨论】:

  • 请将代码和数据添加为文本 (using code formatting),而不是图像。图片:A)不允许我们复制粘贴代码/错误/数据进行测试; B) 不允许根据代码/错误/数据内容进行搜索;和many more reasons。除了代码格式的文本之外,只有在图像添加了一些重要的东西,而不仅仅是文本代码/错误/数据传达的内容时,才应该使用图像。

标签: spring-boot jasper-reports export-to-pdf


【解决方案1】:

您可以创建一个目录并获取该目录的绝对路径,然后将pdf导出到创建的目录。

在 Windows 机器上,例如:-

File file = new File("C:/temp/output");
file.mkdirs();
  JasperExportManager.exportReportToPdfFile(print, file.getAbsolutePath 
+"report.pdf");

在 Linux 机器上:-

File file = new File("/opt/output");

file.mkdirs();
  JasperExportManager.exportReportToPdfFile(print, file.getAbsolutePath 
+"report.pdf");

【讨论】: