小编Lui*_*ira的帖子

如何在JasperReports 6.1中导出为PDF:使用JRPdfExporter.setParameter方法的替代方法

如何在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();
Run Code Online (Sandbox Code Playgroud)

但是以下代码不适用于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();
Run Code Online (Sandbox Code Playgroud)

我该如何重写此代码?

java jasper-reports export-to-pdf

1
推荐指数
1
解决办法
7726
查看次数

标签 统计

export-to-pdf ×1

jasper-reports ×1

java ×1