目前我在使用cups4j时遇到了一些问题。 例如在linux下你可以在这样的杯子打印机上打印:
echo -e "test Text\\r" | lp -o raw -h <IP-ADRESS> -d <PRINTER-NAME>对我来说重要的是“-o raw”标志。
我的问题是在使用cups4j进行打印时,我不知道如何设置此标志。 剪切下一个正确的工作代码显示了我在CupsPrinter上打印cups4j PrintJob的方法。
private PrintRequestResult print(CupsPrinter printer, PrintJob job) throws Exception { return printer.print(job); }这里描述了 -o raw选项:
-o raw选项允许您直接将文件发送到打印机而无需过滤。 从为您的打印机提供自己的“打印机驱动程序”的应用程序打印时,有时需要这样做:
就像我说的那样,打印本身就像一个魅力,但我不知道如何添加这个特定的标志。 也许有人可以形容我该怎么做。
Currently I have some problems using cups4j. For example under linux you can print on a cups printer like this:
echo -e "test Text\\r" | lp -o raw -h <IP-ADRESS> -d <PRINTER-NAME>Important for me is the "-o raw" flag.
My problem is while priniting with cups4j, I don't know how to set this flag. The next proper working code snipped shows my method that prints a cups4j PrintJob on a CupsPrinter.
private PrintRequestResult print(CupsPrinter printer, PrintJob job) throws Exception { return printer.print(job); }The -o raw option is described here pretty well:
The -o raw option allows you to send files directly to a printer without filtering. This is sometimes required when printing from applications that provide their own "printer drivers" for your printer:
Like I said, printing itself works like a charm, but I have no idea how to add this specific flag. Maybe someone can describe me how to do it.
最满意答案
在通过wireshark(我只是喜欢它)从终端和java程序分析发送给CUPS的包后,我发现以下对我有用:
CupsClient cupsClient = new CupsClient(IP, port); URL url = new URL(printerName); CupsPrinter cupsPrinter = cupsClient.getPrinter(url); HashMap<String, String> map = new HashMap<>(); map.put("document-format", "application/vnd.cups-raw"); PrintJob printJob = new PrintJob.Builder(bytes).attributes(map).build(); PrintRequestResult printRequestResult = cupsPrinter.print(printJob);After analysing the packages sent to CUPS via wireshark (I just love it) from both the terminal and java program I found the following that worked for me:
CupsClient cupsClient = new CupsClient(IP, port); URL url = new URL(printerName); CupsPrinter cupsPrinter = cupsClient.getPrinter(url); HashMap<String, String> map = new HashMap<>(); map.put("document-format", "application/vnd.cups-raw"); PrintJob printJob = new PrintJob.Builder(bytes).attributes(map).build(); PrintRequestResult printRequestResult = cupsPrinter.print(printJob);更多推荐
发布评论