最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Java send printjob to CUPS (socket printer) - Stack Overflow

programmeradmin1浏览0评论

I want to send a print job to Cups and the printer is connected to CUPS via socket. I am looking for a solution for my Java program to send print jobs to the printer using a URL to CUPS.

CUPS: http://CUPS-IP-ADDRESS:631/

Printer: socket://PRINTER-IP-ADDRESS:PORT

I tried a few packages to send print jobs to the printer. But nothing works. I think the problem is that all packages want an IPP printer, but the printer can't use IPP. Also, the printer can't print PDFs. That's why I need CUPS to do it.

Packages I tried:

ipp-client

<dependency>
    <groupId>de.gmuth</groupId>
    <artifactId>ipp-client</artifactId>
    <version>3.2</version>
</dependency>

cups4j

<dependency>
    <groupId>.cups4j</groupId>
    <artifactId>cups4j</artifactId>
    <version>0.7.9</version>
</dependency>

j4cups

<dependency>
    <groupId>de.javatux</groupId>
    <artifactId>j4cups</artifactId>
    <version>0.6.1</version>
</dependency>

For some reason, my printer cannot be found by the Java packages, especially printers that are registered as IPP and have IPP as a feature.

I have CUPS in a Docker container, so I need the CUPS-IP-ADDRESS for CUPS. When I use the CMD-Line lp -d MyPrinter srv/MyFile.pdf, the print job prints correctly.

If I use a CMD-Line to send a raw-file via telnet,curl -v --upload-file srv/MyFile.raw-file telnet://PRINTER-IP-ADDRESS:PORT, that also works. So I would expect that Java's socket class would do the same thing correctly with raw-files.

But I want to do it with PDFs because the raw-files are complicated to create and PDFs are much easier. So can someone help me send a print job to CUPS for my socket-connected printer? I couldn't find any documentation on this, only for IPP printers. It shouldn't be that hard to send a print job to CUPS via an URL, but I haven't found out how to do it yet.

I want to send a print job to Cups and the printer is connected to CUPS via socket. I am looking for a solution for my Java program to send print jobs to the printer using a URL to CUPS.

CUPS: http://CUPS-IP-ADDRESS:631/

Printer: socket://PRINTER-IP-ADDRESS:PORT

I tried a few packages to send print jobs to the printer. But nothing works. I think the problem is that all packages want an IPP printer, but the printer can't use IPP. Also, the printer can't print PDFs. That's why I need CUPS to do it.

Packages I tried:

ipp-client

<dependency>
    <groupId>de.gmuth</groupId>
    <artifactId>ipp-client</artifactId>
    <version>3.2</version>
</dependency>

cups4j

<dependency>
    <groupId>.cups4j</groupId>
    <artifactId>cups4j</artifactId>
    <version>0.7.9</version>
</dependency>

j4cups

<dependency>
    <groupId>de.javatux</groupId>
    <artifactId>j4cups</artifactId>
    <version>0.6.1</version>
</dependency>

For some reason, my printer cannot be found by the Java packages, especially printers that are registered as IPP and have IPP as a feature.

I have CUPS in a Docker container, so I need the CUPS-IP-ADDRESS for CUPS. When I use the CMD-Line lp -d MyPrinter srv/MyFile.pdf, the print job prints correctly.

If I use a CMD-Line to send a raw-file via telnet,curl -v --upload-file srv/MyFile.raw-file telnet://PRINTER-IP-ADDRESS:PORT, that also works. So I would expect that Java's socket class would do the same thing correctly with raw-files.

But I want to do it with PDFs because the raw-files are complicated to create and PDFs are much easier. So can someone help me send a print job to CUPS for my socket-connected printer? I couldn't find any documentation on this, only for IPP printers. It shouldn't be that hard to send a print job to CUPS via an URL, but I haven't found out how to do it yet.

Share Improve this question asked Feb 10 at 10:13 FelixFeuerdornFelixFeuerdorn 536 bronze badges 2
  • I doubt you need any CUPS-specific packages. You need to google on Streaming print service Java – g00se Commented Feb 10 at 10:57
  • These packages are CUPS-specific. And I can print PDFs with CUPS because CUPS sends the correct format (pdf -> raw format) to the printer. But I can only print it via the command line, not with a URL to CUPS, because I don't know how. – FelixFeuerdorn Commented Feb 10 at 11:06
Add a comment  | 

1 Answer 1

Reset to default 0

I solved it.

My problem was that the printer I had registered in CUPS was not authorized for external commands. The only thing I had to do was set the property printer-is-shared to true to authorize the printer.

First check the MyPrinter options in CUPS: lpoptions -p MyPrinter

Then change the option: lpadmin -p MyPrinter -o printer-is-shared=true

Finally, restart the CUPS server

发布评论

评论列表(0)

  1. 暂无评论