【问题标题】:Print Jasper Report Using a Printer使用打印机打印 Jasper 报告
【发布时间】:2016-11-12 06:11:13
【问题描述】:

我正在使用 Jasper 报告创建一个报告,并将其保存为驱动器中的 pdf 文件。我想使用该报告的打印机打印出来。 经过简短的谷歌搜索后,我发现有两种方法可以做到这一点。 1)在打印预览模式下打开pdf然后打印 2) 将 jasperPrint 文件直接发送到打印机。

下面是我到目前为止所做的代码。有人可以指导我在 Java Web 应用程序中使用 Java 执行上述方法之一。谢谢。

public int printCashReceipt(){
try{
   Connection connection = util.DatabaseConnection.getDbConnection();
   JasperReport jasperReport = JasperCompileManager.compileReport(getClass().getResourceAsStream("../reports/ReceiptCash.jrxml"));

   Map<String, Object> map = new HashMap<>();
   map.put("receipt_id", 6);

   JasperPrint jp = JasperFillManager.fillReport(jasperReport, map, connection);

   File outDir = new File("C:/reports");
   outDir.mkdirs();

   JasperExportManager.exportReportToPdfFile(jp, "C:/reports/ReceiptCash.pdf");
   System.out.println("Done!");
   connection.close();

   return 1;
   }
   catch(Exception e){
       System.out.println(e);
       return 0;
   }   

}

【问题讨论】:

标签: java printing jasper-reports


【解决方案1】:

你可以试试这个

JasperPrint print = JasperFillManager.fillReport(jp, parameters, jrBeanDatasource);     
JasperViewer.viewReport(print, true);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多