gpt4 book ai didi

java - 如何在 JasperReports 6.1 : alternate of using JRPdfExporter. setParameter 方法中导出为 PDF

转载 作者:行者123 更新时间:2023-11-29 06:57:10 25 4
gpt4 key购买 nike

如何在 JasperReports 6.1 中导出为 PDF?

我将这段代码与 JasperReports API 5.2 一起使用:

JasperPrint jasperPrint = JasperFillManager.fillReport(getServletContext().getRealPath(url), parametros, new JRBeanCollectionDataSource(listadoDatos));
JRExporter exporter = new JRPdfExporter();
exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, out);
exporter.exportReport();

但是下面的代码不适用于JR API 6.1:

  JasperPrint jasperPrint;  
if (conConexion) {
jasperPrint = JasperFillManager.fillReport(getServletContext().getRealPath(url), parametros, conexion);
conexion.close();
} else {
jasperPrint = JasperFillManager.fillReport(getServletContext().getRealPath(url), parametros, new JRBeanCollectionDataSource(listaDatos));
}
JRPdfExporter exporter = new JRPdfExporter();
exporter.setExporterInput(new SimpleExporterInput(jasperPrint));
exporter.setExporterOutput(new SimpleOutputStreamExporterOutput(nombreReporte+".pdf"));
SimplePdfExporterConfiguration configuration = new SimplePdfExporterConfiguration();
exporter.setConfiguration(configuration);
exporter.exportReport();

如何重写这段代码?

最佳答案

@LuisNeira 的回答

这是解决方案:

JRPdfExporter exporter = new JRPdfExporter();
exporter.setExporterInput(new SimpleExporterInput(jasperPrint));
exporter.setExporterOutput(new SimpleOutputStreamExporterOutput(outputStream));
SimplePdfExporterConfiguration configuration = new SimplePdfExporterConfiguration();
configuration.setPermissions(PdfWriter.AllowCopy | PdfWriter.AllowPrinting);
exporter.setConfiguration(configuration);
exporter.exportReport();

关于java - 如何在 JasperReports 6.1 : alternate of using JRPdfExporter. setParameter 方法中导出为 PDF,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32318421/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com