///
/
public void print(String printerName) {
// 文档
Book book = new Book();
// 设置成竖打
PageFormat pf = new PageFormat();
pf.setOrientation(PageFormat.PORTRAIT);
// 通过Paper设置页面的空白边距和可打印区域。必须与实际打印纸张大小相符。
Paper p = new Paper();
p.setSize(225, 85);// 纸张大小 80mm/(25.4mm/72)
p.setImageableArea(marginLeft, marginTop, 215, 80);// 打印范围
pf.setPaper(p);
// 把 PageFormat 和 Printable 添加到书中,组成一个页面
book.append(printContent, pf);
网上指定打印机都是使用DocPrinterJob 到外网查了下资料 改写了一个
///
// 获取打印服务对象
PrinterJob job = PrinterJob.getPrinterJob();
// 查找指定的打印机
if (null != printerName) {// 不指定的话会调用默认的打印机
PrintService[] printServices = PrintServiceLookup.lookupPrintServices(null, null);
logger.debug("input printer name:" + printerName);
for (int i = 0; i < printServices.length; i++) {
String svcName = printServices[i].toString();
// logger.debug("print service:" + s
JAVA PrinterJob 指定打印机
最新推荐文章于 2024-08-01 12:02:03 发布