首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >从Java打印失败,显示'pstopdffilter/pstocupsraster failed with err number -31000‘

从Java打印失败,显示'pstopdffilter/pstocupsraster failed with err number -31000‘
EN

Stack Overflow用户
提问于 2012-07-29 23:07:58
回答 2查看 735关注 0票数 1

在Mac OS X 10.8.0上尝试使用以下Java代码打印JPEG文件时,收到错误消息:

代码语言:javascript
复制
Error: pstopdffilter/pstocupsraster failed with err number 31000

谷歌搜索的建议似乎暗示问题不是直接与Java有关,例如http://forum.parallels.com/showthread.php?t=106337

代码语言:javascript
复制
/**
 * http://stackoverflow.com/questions/7843338/printing-a-tif-file
 * 
 * @param graphicFile
 * @throws PrintException
 * @throws IOException
 */
public void printGraphic(File graphicFile) throws PrintException,
        IOException {

    PrintRequestAttributeSet pras = new HashPrintRequestAttributeSet();
    pras.add(new Copies(1));
    pras.add(Chromaticity.COLOR);
    pras.add(MediaSizeName.ISO_A4);
    PrintService pss[] = PrintServiceLookup.lookupPrintServices(
            DocFlavor.INPUT_STREAM.JPEG, pras);

    if (pss.length == 0)
        throw new RuntimeException("No printer services available.");

    PrintService ps = pss[0];
    System.out.println("Printing to " + ps);
    DocPrintJob job = ps.createPrintJob();
    FileInputStream fin = new FileInputStream(graphicFile);
    Doc doc = new SimpleDoc(fin, DocFlavor.INPUT_STREAM.JPEG, null);
    job.print(doc, pras);
    fin.close();
}
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2012-10-19 15:20:09

作为一种变通办法,我建议使用而不是tiff。

代码语言:javascript
复制
/**
 * 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);
        }
    }
}
票数 2
EN

Stack Overflow用户

发布于 2012-10-19 16:33:19

你说你正在“尝试打印一个JPEG文件”。

但是,错误消息表明CUPS ( Mac打印子系统)试图通过pstopdffilter (将PostScript转换为PostScript的实用程序)或pstocupsraster (将PostScript转换为CUPS-raster的实用程序)运行打印作业。

您应该首先启用LogLevel debug (编辑/私有/etc/ CUPS /cupsd.conf并重启CUPS打印服务)。

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

代码语言:javascript
复制
Auto-typing file...
Request file type is
Started filter
Started backend
exited with
failed with

您的调查结果可能与以下内容类似:

代码语言:javascript
复制
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错误的行,例如:

代码语言:javascript
复制
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. ] %%

在这种情况下,你的输入文件可能是错误的,可能是太大了,或者其他什么…

一般来说,重要的是要知道:

  1. 打印服务的“自动键入”功能为打印作业的mime类型返回了什么?
  2. 在pstopdffilter (或pstocupsraster)发挥作用之前,筛选器链中运行了哪些筛选器(如果有)?
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/11710300

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档