加载模板
JasperPrint jasperPrint = JasperFillManager.fillReport("WebRoot/report/test.jasper", new HashMap(),new JREmptyDataSource());//false/true 表示在打印的时候是否显示打印机设置JasperPrintManager.printReport(jasperPrint, false);
设置指定打印机
PrintService[] pss = PrinterJob.lookupPrintServices();PrintService ps = null;for (int i = 0; i < PSs.length; i++) {String sps = PSs[i].toString();//如果打印机名称相同if(sps.equalsIgnoreCase("Win32 Printer : pdfFactory Pro")){ps = PSs[i];}}JRAbstractExporter je = new JRPrintServiceExporter();je.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);//设置指定打印机je.setParameter(JRPrintServiceExporterParameter.PRINT_SERVICE, ps);je.setParameter(JRPrintServiceExporterParameter.DISPLAY_PAGE_DIALOG, false);je.setParameter(JRPrintServiceExporterParameter.DISPLAY_PRINT_DIALOG, false);//打印je.exportReport();