Print to specific printer (IPP URI) in Java

后端 未结 3 429
悲哀的现实
悲哀的现实 2020-12-01 03:59

Is there any way in Java to print to a specific IPP printer? All of the sample code and tutorials I\'ve found focus on how to print a particular type of document, using some

3条回答
  •  旧巷少年郎
    2020-12-01 04:37

    I finally found a way to do this, by using jipsi:

    URI printerURI = new URI("ipp://SERVER:631/printers/PRINTER_NAME");
    IppPrintService svc = new IppPrintService(printerURI);
    InputStream stream = new BufferedInputStream(new FileInputStream("image.epl"));
    DocFlavor flavor = DocFlavor.INPUT_STREAM.AUTOSENSE;
    Doc myDoc = new SimpleDoc(stream, flavor, null);
    DocPrintJob job = svc.createPrintJob();
    job.print(myDoc, null);
    

    I have to admit I'm disappointed at having to use a 3rd-party library to do something so seemingly simple as printing to a specific printer.

    UPDATE

    DR points out in the comments that jipsi has a new home, and a new name.

    Cups4J is a nice alternative, but as the name implies it may not work correctly if the destination is not a CUPS server. I have had good results using Cups4J to print directly to a Zebra thermal printer.

提交回复
热议问题