Swing Print on Mac and Windows - Where is the postscript support?

I am printing a complex swing app UI for a physical printer via an airport. I have Mac and windows computers that print to the same printer. Mac printing looks great. Printing from windows looks far from perfect - everything is very uneven, including fonts and graph lines.

Several companies show that the available PrintServices differ for different platforms.

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

      

When executed from a macro, the above returns a singleton array. From windows, it returns an empty array. This makes me think that windows are sending 72 DPI to the printer instead of postscript data.

Is this the difference in JVM implementations for Mac and Windows? Is there a workaround for how Windows works? I realize I can create my own 350 dpi bitmap and send it to the printer, but these things end up in hundreds of pages, I really would like to avoid this route if possible.

+1


a source to share


1 answer


I think I have an answer: the system property java.awt.printerjob

was set to sun.awt.windows.WPrinterJob

. This appears to be a handy subclass of PrinterJob if you like blocky pixel output on your printer. Instead, I get an instance sun.print.PSPrinterJob

if available, for example:



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();
}

      

+1


a source







All Articles