Java Printing on Unix is flakey, even on 1.4.2!

Datetime:2016-08-22 22:46:23          Topic: Unix  Java           Share

Geez - I was just starting to be so happy for the Java Printing Service API. It works like a charm under Windows.

The following code list all printers available AND which trays that are available.

Works fine on Windows, but NOT on Solaris or even Linux ;(





        // Get a list of printservices.

        PrintService[] services = PrintServiceLookup.lookupPrintServices(null, null);


        for (int i = 0; i < services.length; i++) {

            PrintService service = services[i];

            System.out.println(service);

            DocFlavor flavor = DocFlavor.SERVICE_FORMATTED.PAGEABLE;

            Class category = Media.class;

            Object o = service.getSupportedAttributeValues(category, flavor, null);

            if (o == null) {

                // Attribute is not supported           

            } else if (o.getClass().isArray()) {

                // Attribute values are a set of values

                Media[] media = (Media[]) o;

                for (int j = 0; j < media.length; j++) {

                    if(media[j] instanceof MediaTray)  {

                        System.out.println(media[j]);

                    }

                }

            }


        }


The reason ? SUN's own implementation of UnixPrintService and PSPrintJob (internal parts of the JDK) does neither lookup tray information nor do they listen to any tray information provided to them. Thus...

You CANNOT print to a given tray on Solaris ;(

This was supposed to have been fixed in JDK 1.4.2 according to #4701198 and #4707777 on bug parade - but no luck so far ;(

The workaround is to provide your own implementation of these basic printservices which utilizes the

correct lpr and lpoptions commands - but these classes needs to be on the bootclasspath!!!

Come on Sun - please provide a reasonable print functionality on your own platforms!





About List