[英]How can I export to PDF in JasperReports 6.1: alternate of using JRPdfExporter.setParameter method
如何在 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();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.