1.[现有]帮助文档调默认打印机 // 定义报表运行环境,才能执行报表 String envPath = onLinePoint; FRContext.setCurrentEnv(new LocalEnv(envPath)); try { TemplateWorkBook workbook = TemplateWorkBookIO.readTemplateWorkBook(FRContext.getCurrentEnv(), fileName+".cpt"); // 参数传值 Parameter[] parameters = workbook.getParameters(); HashMap<String, String> paraMap = new HashMap<String, String>(); paraMap.put(parameters[0].getName(), packCode); // java中调用报表打印方法 boolean a = PrintUtils.printWorkBook(fileName+".cpt", paraMap, false); if (a == false) { System.out.println("失败啦!返回" + a); this.returnData.toSuccess("打印封箱单失败!"); } else { this.returnData.toSuccess("打印封箱单成功!"); System.out.println("成功!返回" + a); } } catch (Exception e) { e.printStackTrace(); } 2.需求调用指定打印机 [PrintUtils] public static void print(PrintableSet printableset, boolean flag, String s) throws PrinterException { print(printableset, flag, s, 0); } public static void print(PrintableSet printableset, boolean flag, String s, int i) throws PrinterException { PrintService printservice = null; if(s != null) { PrintService aprintservice[] = PrintServiceLookup.lookupPrintServices(javax.print.DocFlavor.INPUT_STREAM.AUTOSENSE, null); int j = 0; do { if(j >= aprintservice.length) break; if(s.equals(aprintservice[j].getName())) { printservice = aprintservice[j]; break; } j++; } while(true); } if(printservice == null) printservice = PrintServiceLookup.lookupDefaultPrintService(); PrinterJob printerjob = PrinterJob.getPrinterJob(); if(printservice != null) printerjob.setPrintService(printservice); if(printableset.size() == 0) { return; } else { getPageablePrintBook(printerjob, printableset, printservice, flag, i); printerjob.print(); return; } } 3.问:上面方法是否能满足需求; 参数中PrintableSet如何使用、String s 是否打印机名称; 具体实现步骤。 |
0
|
|