使用';从Java打印失败;pstopdffilter/pstocupsraster失败,错误号为-31000';

使用';从Java打印失败;pstopdffilter/pstocupsraster失败,错误号为-31000';,java,macos,printing,Java,Macos,Printing,在Mac OS X 10.8.0上尝试使用下面的Java代码打印JPEG文件时,我发现 错误消息: Error: pstopdffilter/pstocupsraster failed with err number 31000 Gooogle搜索带来了一些建议,这些建议似乎暗示问题不直接与Java有关 例如 作为一种解决方法,我建议使用jpeg而不是tiff。 /** * http://stackoverflow.com/questions/5338423/print-a-image-w

在Mac OS X 10.8.0上尝试使用下面的Java代码打印JPEG文件时,我发现 错误消息:

Error: pstopdffilter/pstocupsraster failed with err number 31000
Gooogle搜索带来了一些建议,这些建议似乎暗示问题不直接与Java有关 例如


作为一种解决方法,我建议使用jpeg而不是tiff。

/**
 * http://stackoverflow.com/questions/5338423/print-a-image-with-actual-size
 * -in-java
 * 
 * @param graphicFile
 */
public void printG(File graphicFile) {
    final Image img = new ImageIcon(graphicFile.getAbsolutePath())
            .getImage();
    PrinterJob printJob = PrinterJob.getPrinterJob();
    Printable printable = new Printable() {
        public int print(Graphics graphics, PageFormat pageFormat,
                int pageIndex) throws PrinterException {
            if (pageIndex != 0) {
                return NO_SUCH_PAGE;
            }
            graphics.drawImage(img, 0, 0, img.getWidth(null),
                    img.getHeight(null), null);
            return PAGE_EXISTS;
        }
    };
    printJob.setPrintable(printable, getPageFormat());
    if (printJob.printDialog()) {
        try {
            printJob.print();
        } catch (Exception prt) {
            handle(prt);
        }
    }
}
您说您正在“尝试打印JPEG文件”

但是,错误消息表明CUPS(Mac OS X打印子系统)试图通过
pstopdffilter
(将PostScript转换为PDF的实用程序)或
psTopSgraster
(将PostScript转换为CUPS光栅的实用程序)运行打印作业

您应该首先启用日志级调试(编辑/private/etc/cups/cupsd.conf并重新启动cups打印服务)

然后,在CUPS日志文件(*/var/log/CUPS/error_log*)中查找包含以下字符串的行:

Auto-typing file...
Request file type is
Started filter
Started backend
exited with
failed with
您的发现可能与以下类似:

D [...timestamp...] [Job 9] Auto-typing file...
D [...timestamp...] [Job 9] Request file type is image/jpeg.
I [...timestamp...] [Job 9] Started filter /usr/libexec/cups/filter/imagetops (PID 25690)
I [...timestamp...] [Job 9] Started filter /usr/libexec/cups/filter/pstops (PID 25691)
I [...timestamp...] [Job 9] Started filter /usr/libexec/cups/filter/pstopdffilter (PID 25694)
I [...timestamp...] [Job 9] Started backend /usr/libexec/cups/backend/2dir (PID 25695)
D [...timestamp...] PID 25690 (/usr/libexec/cups/filter/imagetops) exited with no errors.
D [...timestamp...] PID 25691 (/usr/libexec/cups/filter/pstops) exited with no errors.
E [...timestamp...] PID 25694 (/usr/libexec/cups/filter/pstopdffilter) failed with err number -31000.
D [...timestamp...] PID 25695 (/usr/libexec/cups/backend/2dir) exited with no errors.
我说“类似于以下内容”,因为我的水晶球正在维修中,您没有提供有关打印环境设置的任何其他详细信息,没有这些信息,将无法进一步分析您的问题

另外,在日志文件中查找指示PostScript错误的行,例如:

D [...timestamp...] [Job 9] %%[ Error: ioerror; OffendingCommand: image ]%%
D [...timestamp...] [Job 9] 
D [...timestamp...] [Job 9] Stack:
D [...timestamp...] [Job 9] -dict-
D [...timestamp...] [Job 9] 
D [...timestamp...] [Job 9] %%[ Flushing: rest of job (to end-of-file) will be ignored ]%%
D [...timestamp...] [Job 9] 
D [...timestamp...] [Job 9] %%[ Warning: PostScript error. No PDF file produced. ] %%
在这种情况下,您的输入文件可能有错误,可能太大或其他什么

一般而言,重要的是了解:

  • 打印服务的“自动键入”功能为打印作业的mime类型返回了什么
  • 在pstopdffilter(或pstocupsraster)发挥作用之前,过滤器链中已经运行了哪些过滤器(如果有)

  • 你打印的所有JPEG作业都会发生这种情况吗?还是只是一些?我已经取消了悬赏,因为有共谋的迹象。如果不是这样的话,我建议你提出来,但是在一分钟内(看起来是11秒)只接受一个代码答案是非常可疑的。完全可以。我最近就发布已知答案的问题展开了一场元讨论。@WolfgangFahl您似乎承认在这里所做的事情一点也不好;你应该把答案放在与问题相同的账户下。相反,你通过第二个账户人为地赢得了声誉。不,我们复制了真实情况。我有个问题,我儿子已经解决了。。。发布一个答案并在11秒内获得投票、接受(以及再次投票)必须是一个新记录。请参阅关于发布已知问题的已知解决方案的元讨论。。。问答形式对此毫无用处。但大多数人似乎有不同的想法。这很奇怪,你怎么会在11秒内知道这就是答案?看来有一些勾结。这是不允许的。你和@WolfgangFahl之间有关系吗?表面上似乎有。请看元讨论。我们公司有几千篇关于已经解决的问题的文章,不知何故,这里的问答格式和规则是分享这些问题的障碍。@WolfgangFahl分享这些问题及其解决方案很好。但是,人为地提高来自同一实体的多个用户的声誉是不行的。您应该自己发布解决方案,与您发布问题时使用的帐户相同。感谢您的建议-我将不得不推迟我们的解决方案来测试此问题-请继续关注。。。
    D [...timestamp...] [Job 9] %%[ Error: ioerror; OffendingCommand: image ]%%
    D [...timestamp...] [Job 9] 
    D [...timestamp...] [Job 9] Stack:
    D [...timestamp...] [Job 9] -dict-
    D [...timestamp...] [Job 9] 
    D [...timestamp...] [Job 9] %%[ Flushing: rest of job (to end-of-file) will be ignored ]%%
    D [...timestamp...] [Job 9] 
    D [...timestamp...] [Job 9] %%[ Warning: PostScript error. No PDF file produced. ] %%