JDK-6520478 : Use HTTP instead of lpr for sending print data in CUPS
  • Type: Enhancement
  • Component: client-libs
  • Sub-Component: 2d
  • Affected Version: 5.0
  • Priority: P4
  • Status: Open
  • Resolution: Unresolved
  • OS: generic
  • CPU: generic
  • Submitted: 2007-02-01
  • Updated: 2016-03-22
Related Reports
Relates :  
Description
This is related to bug 6520121.  Problem occurs when we connect successfully to CUPS server but the path of lpr differs from the JDK assumption that it is in /usr/bin so we get an exception during printing.  This can be avoided if we use HTTP for sending print data to printer. 

To reproduce, run the following program:

import java.awt.*;
import javax.print.*;
import javax.print.attribute.*;
import javax.print.attribute.standard.*;
import java.awt.print.*;
import java.io.*;

public class HeadlessPrintingTest {

    public static void main(String[] args) {
        System.setProperty("java.awt.headless", "true");
        PrinterJob pj = PrinterJob.getPrinterJob();
        pj.setPrintable(new Printable() {
            public int print(Graphics g, PageFormat pg, int pageIndex) {
                Graphics2D g2d = (Graphics2D)g;
                if (pageIndex > 2) {
                    return Printable.NO_SUCH_PAGE;
                } else {
                    g2d.translate(pg.getImageableX(), pg.getImageableY());
                    g2d.setColor(Color.RED);
                    g2d.drawString("page " + pageIndex, 100, 100);
                    return Printable.PAGE_EXISTS;
                }
            }
        });

        try {           
            pj.print();
        } catch (Exception e) {
        e.printStackTrace();
        }
    }
}