繁体   English   中英

如何列印报告

[英]How to print report

我想打印一个JR报告。

我正在尝试此代码

JasperPrint jp = new JasperFillManager().fillReport("billReport", billId, 
    "jdbc:mysql://localhost/kpc_hospital");  
JasperPrintManager.printReport(jp, true)

但是此代码不起作用。

您可以使用多种方法直接打印Jasper Report,而不显示“打印对话框”。

最简单的方法是:

    Connection con;
    String url="jdbc:mysql://localhost/mydb";
    Class.forName("com.mysql.jdbc.Driver").newInstance();
    con=(Connection) DriverManager.getConnection(url,"root","");
    JasperReport jasperReport = JasperCompileManager.compileReport(fileName);
    JasperPrint print = JasperFillManager.fillReport(jasperReport, parameter, con);
    print.setPageHeight(100);
    print.setPageWidth(80);
    print.setOrientation(jasperReport.getOrientationValue().LANDSCAPE);
    JasperPrintManager.printReport(print,false);

您还可以使用以下命令:

    PrinterJob job = PrinterJob.getPrinterJob();
    int selectedService = 0;
    selectedService = 0;
    PrintRequestAttributeSet printRequestAttributeSet = new HashPrintRequestAttributeSet();
    printRequestAttributeSet.add(OrientationRequested.PORTRAIT);
    printRequestAttributeSet.add(MediaSizeName.ISO_A0); 
    MediaSizeName mediaSizeName = MediaSize.findMedia(64,25,MediaPrintableArea.MM);
    printRequestAttributeSet.add(mediaSizeName);
    printRequestAttributeSet.add(new Copies(1));
    JRPrintServiceExporter exporter;
    exporter = new JRPrintServiceExporter();
    exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasper_print);
    exporter.setParameter(JRPrintServiceExporterParameter.PRINT_REQUEST_ATTRIBUTE_SET, printRequestAttributeSet);
    exporter.setParameter(JRPrintServiceExporterParameter.DISPLAY_PAGE_DIALOG, Boolean.FALSE);
    exporter.setParameter(JRPrintServiceExporterParameter.DISPLAY_PRINT_DIALOG, Boolean.TRUE);
    exporter.exportReport();
    job.print(printRequestAttributeSet);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM