java - pos打印机CUP服务器Ubuntu 16的打印问题
问题描述
我在 Ubuntu 16 上安装了 cups 服务器,安装了 POS 打印机后,经过测试页面和 lpr 命令行命令的测试,它工作正常;在使用PrintJob的java中,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;
}
}
推荐阅读
- c++ - C++ 从日期字符串解析时区
- r - R 包“ElemStatLearn”不可用(对于 R 版本 3.6.3)是否有任何替代方案可用
- python - Python:从列表中写入 .gz 压缩文件
- java - HLS 播放问题
- python - 如何循环遍历模型 Python 中的字符串?
- sql - SQL Server - 获取删除了分钟和秒的日期时间(仅限日期和小时)
- python - 如何将 word2vec 生成的特征与 VGGNet 生成的特征连接起来
- java - 是否可以恢复父类的重写方法?
- python - Python:时间关键循环内的内联代码
- node.js - 如何使用 curl 发布 Json?SyntaxError:位置 1 处 JSON 中的意外标记 n