views:

106

answers:

1

I'm printing a complicated swing application UI to a physical printer via an Airport. I've got Mac & windows machines both printing to the same printer. Printing from the Mac looks great. Printing from windows looks far from great - everything is very pixelated, including fonts and graph lines.

Some digging around reveals that the available PrintServices are different for the different platforms.

DocFlavor flavor = DocFlavor.INPUT_STREAM.POSTSCRIPT;
PrintRequestAttributeSet attrs = new HashPrintRequestAttributeSet();
PrintServiceLookup.lookupPrintServices(flavor, attrs);

When executed from the mac, the above returns a single-element array. From windows, it returns an empty array. This leads me to believe that windows is sending a 72 DPI image to the printer, instead of postscript data.

Is this a difference in the mac & windows JVM implementations? Is there any workaround to get printing on Windows working? I realize I could generate my own 350dpi rasterized image and send that to the printer, but these things go into the hundreds of pages, I really would like to avoid that route if possible.

A: 

Think I got an answer: The java.awt.printerjob system property was set to sun.awt.windows.WPrinterJob. Apparently this is a handy PrinterJob subclass if you like blocky pixelated output on your printer. Instead, I get an instance of sun.print.PSPrinterJob if it's available, like so:

PrinterJob printerJob = null;
try {
    if (System.getProperty("java.awt.printerjob").equals("sun.awt.windows.WPrinterJob")) {
     // WPrinterJob sends crappy GIF images to the printer, and everything looks all blocky
     // try to get an instance of a PSPrinterJob instead
     printerJob = (PrinterJob) Class.forName("sun.print.PSPrinterJob").newInstance();
    }
} catch (Throwable e1) {
    log.log(Level.SEVERE, "Could not instaniate sun.print.PSPrinterJob", e1);
}
if (printerJob == null) {
      printerJob = PrinterJob.getPrinterJob();
}
Sam Barnum