如何在Cups4J中创建一个原始(

编程入门 行业动态 更新时间:2024-10-18 12:26:07
如何在Cups4J中创建一个原始(-o raw)PrintJob?(How to create a raw (-o raw) PrintJob in Cups4J?)

目前我在使用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);

更多推荐

本文发布于:2023-07-22 09:43:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1219089.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:创建一个   原始   如何在   Cups4J

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!