Reputation: 711
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.
Upvotes: 1
Views: 2724
Reputation: 341
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);
Upvotes: 4