Java 无法打印特定打印机-jasper报告
我有两台打印机连接到我的PC COM端口3和4 名称:打印机_aa1、打印机_bb2 我想选择并按此打印机名称或任何索引(如0和1)打印jasper文档 我的代码仅从默认打印机打印。我不能选择任何打印机。 请帮我解决这个问题 多谢各位Java 无法打印特定打印机-jasper报告,java,printing,jasper-reports,Java,Printing,Jasper Reports,我有两台打印机连接到我的PC COM端口3和4 名称:打印机_aa1、打印机_bb2 我想选择并按此打印机名称或任何索引(如0和1)打印jasper文档 我的代码仅从默认打印机打印。我不能选择任何打印机。 请帮我解决这个问题 多谢各位 public void printReciept_non(int printer) { String reportSource = "receipt_non.jrxml"; //sale_report_new Map<String, Ob
public void printReciept_non(int printer) {
String reportSource = "receipt_non.jrxml"; //sale_report_new
Map<String, Object> parameter = new HashMap<String, Object>();
parameter.put("total_amount", priceWithDecimal(totalAmount));
parameter.put("order_code", lbl_orderNo.getText());
parameter.put("table_no", tableNo);
parameter.put("IS_IGNORE_PAGINATION", true);
Locale locale = new Locale("en", "US");
parameter.put(JRParameter.REPORT_LOCALE, locale);
try {
JasperReport js = JasperCompileManager.compileReport(reportSource);
JasperPrint jp = JasperFillManager.fillReport(js, parameter, new check().getConn());
JasperPrintManager.printReport(jp, false);
PrinterJob printerJob = PrinterJob.getPrinterJob();
PrintService[] services = PrintServiceLookup.lookupPrintServices(null, null);
int selectedService = printer;
PrintService[] printService = PrintServiceLookup.lookupPrintServices(null, null);
try {
printerJob.setPrintService(printService[selectedService]);
} catch (Exception e) {
System.out.println(e);
}
PrintRequestAttributeSet printRequestAttributeSet = new HashPrintRequestAttributeSet();
printRequestAttributeSet.add(MediaSizeName.NA_LETTER);
printRequestAttributeSet.add(new Copies(0));
JRPrintServiceExporter exporter = new JRPrintServiceExporter();
exporter.setParameter(JRExporterParameter.JASPER_PRINT, jp);
exporter.setParameter(JRPrintServiceExporterParameter.PRINT_SERVICE, services[selectedService]);
exporter.setParameter(JRPrintServiceExporterParameter.PRINT_SERVICE_ATTRIBUTE_SET, services[selectedService].getAttributes());
exporter.setParameter(JRPrintServiceExporterParameter.PRINT_REQUEST_ATTRIBUTE_SET, printRequestAttributeSet);
exporter.setParameter(JRPrintServiceExporterParameter.DISPLAY_PAGE_DIALOG, Boolean.FALSE);
exporter.setParameter(JRPrintServiceExporterParameter.DISPLAY_PRINT_DIALOG, Boolean.FALSE);
exporter.exportReport();
} catch (Exception e) {
System.out.println(e);
}
}