我在Ubuntu 16上安装了cups服务器,安装了POS打印机后,经过测试测试页和lpr命令行命令,工作正常;在java中使用PrintJob,java找到打印机,但没有打印机任何东西....
解决这个问题的一些想法?
最佳答案
我前段时间也遇到过同样的问题,我这样做了,也许可以帮助你。让我知道。
public static boolean imprimirDocto(String documentPath, String printerName) {
File f = new File(documentPath);
try {
PDDocument doc = PDDocument.load(f);
PrinterJob pj = PrinterJob.getPrinterJob();
PrintService[] ps = PrintServiceLookup.lookupPrintServices(null, null);
PrintService printService = null;
if (ps.length > 0) {
//This searchs for all the printers, and looks for the 'printerName'
for (int i = 0; i < ps.length; i++) {
System.out.println("Printer name: " + ps[i]);
if (ps[i].getName().toLowerCase().contains(printerName.toLowerCase())
|| ps[i].getName().contains(printerName)) {
printService = ps[i];
System.out.println("Setting the printer...");
pj.setPrintService(printService);
i = ps.length;
}
}
pj.setPageable(new PDFPageable(doc));
pj.print();
return true;
} else {
return false;
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
return false;
}
}
关于java - pos打印机CUP服务器Ubuntu 16的打印问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53228160/