在Mac&amp ;; Windows - postscript支持在哪里?

时间:2009-05-21 22:19:01

标签: java windows swing printing postscript

我正在通过机场向物理打印机打印复杂的swing应用程序UI。我有Mac& Windows机器都打印到同一台打印机。从Mac打印看起来很棒。从Windows打印看起来很不错 - 一切都是非常像素化的,包括字体和图形线。

一些挖掘表明,不同平台的可用PrintServices不同。

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

从mac执行时,上面返回单元素数组。从Windows中,它返回一个空数组。这让我相信Windows正在向打印机发送72 DPI图像,而不是后记数据。

这是mac和amp;的区别吗? windows JVM实现?是否有任何解决方法可以在Windows上进行打印?我意识到我可以生成自己的350dpi光栅化图像并将其发送到打印机,但这些东西会进入数百页,如果可能的话我真的想避开这条路线。

1 个答案:

答案 0 :(得分:1)

我想我得到了答案:java.awt.printerjob系统属性设置为sun.awt.windows.WPrinterJob。显然,如果您喜欢打印机上的块状像素化输出,这是一个方便的PrinterJob子类。相反,如果可用,我会得到sun.print.PSPrinterJob的实例,如下所示:

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