[英]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.