在Mac OSX Lion中使用JPS在Java中打印

在Mac OSX Lion中使用JPS在Java中打印,java,printing,Java,Printing,我正在尝试使用JPS将JPG图像打印到打印机上,但在MacOSX中它总是给我一个错误。它总是说,“无法转换PostScript文件” 下面是我用来打印的代码: final PrintRequestAttributeSet photoAttr = createPhotoPaperPrintAttributes(copies); PrintService printerService = findPrintService(photoAttr); try { D

我正在尝试使用JPS将JPG图像打印到打印机上,但在MacOSX中它总是给我一个错误。它总是说,“无法转换PostScript文件”

下面是我用来打印的代码:

final PrintRequestAttributeSet photoAttr = createPhotoPaperPrintAttributes(copies);
PrintService printerService = findPrintService(photoAttr);
        try {
            DocAttributeSet das = new HashDocAttributeSet();
            das.add(new PrinterResolution(300, 300, PrinterResolution.DPI));
            das.add(MediaSizeName.ISO_A6);
            final Doc doc = new SimpleDoc(new FileInputStream(new File(imageFile)), DocFlavor.INPUT_STREAM.JPEG, das);

            DocPrintJob printJob = printerService.createPrintJob();
            printJob.print(doc, photoAttr);
        } catch (Exception e) {
            throw new PrintException(e);
        }
有人知道可能出了什么问题吗

我设法用一个可打印的界面来打印,但我无法以高于72 DPI的分辨率打印图像。我尝试了一些建议,比如缩放2d图形,但似乎不起作用


如有任何帮助,我们将不胜感激。

仅使用JPS,您将在Mac上遇到问题。 我的建议是使用Java2PrintAPI+JavaPrintService

Java2PrintAPI有点像1990年的风格。为了避免使用Java2PrintAPI创建代码,可以使用PDFBox作为框架

使用PDFBox,您可以创建PDF文档(),但不用保存,而是使用以下代码打印:

PrinterJob printJob = PrinterJob.getPrinterJob();
PrintService service = PrintServiceLookup.lookupDefaultPrintService(); 
printJob.setPrintService(service);      
document.silentPrint(printJob);

它在我的Mac电脑上运行良好。

只使用JPS,你在Mac电脑上会遇到问题。 我的建议是使用Java2PrintAPI+JavaPrintService

Java2PrintAPI有点像1990年的风格。为了避免使用Java2PrintAPI创建代码,可以使用PDFBox作为框架

使用PDFBox,您可以创建PDF文档(),但不用保存,而是使用以下代码打印:

PrinterJob printJob = PrinterJob.getPrinterJob();
PrintService service = PrintServiceLookup.lookupDefaultPrintService(); 
printJob.setPrintService(service);      
document.silentPrint(printJob);

它在我的Mac电脑上运行良好。

现在在任何Mac电脑打印上都可以使用它。你们找到解决方案了吗?并没有,所以我完全放弃了使用java打印api的实现。我所做的只是在任何mac打印上使用本机打印“lp”和“CUPS”驱动器。你们找到解决方案了吗?并没有,所以我完全放弃了使用java打印api的实现。我所做的只是使用本机打印“lp”和“CUPS”驱动程序