try {
// 通俗理解就是书、文档
Book book = new Book();
// 设置成竖打
PageFormat pf = new PageFormat();
pf.setOrientation(PageFormat.PORTRAIT );
// 通过Paper设置页面的空白边距和可打印区域。必须与实际打印纸张大小相符。
Paper paper = new Paper();
paper.setSize(266.8, 30000);// 纸张大小
paper.setImageableArea(10, 15, 266.8, 30000);// A4(595 X
// 842)设置打印区域,其实0,0应该是72,72,因为A4纸的默认X,Y边距是72
pf.setPaper(paper);
book.append(new PrintableAllOrder(orderInfo), pf);
// 获取打印服务对象
PrinterJob job = PrinterJob.getPrinterJob();
// 设置打印类
job.setPageable(book);
//指定XP-80C打印机打印分单
HashAttributeSet hs = new HashAttributeSet();
String printerName=printName;
hs.add(new PrinterName(printerName,null));
PrintService[] pss = PrintServiceLookup.lookupPrintServices(DocFlavor.SERVICE_FORMATTED.PAGEABLE, hs);
if(pss.length==0)
{
System.out.println("无法找到打印机:");
throw new SimpleException("无法找到打印机:");
// return FootResult.ERROR("无法找到打印机");
}
// 获取打印服务对象
//添加指定的打印机
job.setPrintService(pss[0]);
//开始打印
job.print();
} catch (PrinterException e) {
e.printStackTrace();
}
// return FootResult.SUCCESS("已添加到打印队列");
}