在Mac OS X 10.8.0上尝试使用以下Java代码打印JPEG文件时,收到错误消息:
Error: pstopdffilter/pstocupsraster failed with err number 31000谷歌搜索的建议似乎暗示问题不是直接与Java有关,例如http://forum.parallels.com/showthread.php?t=106337
/**
* 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();
}发布于 2012-10-19 15:20:09
作为一种变通办法,我建议使用而不是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);
}
}
}发布于 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*)中查找包含以下字符串的行:
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. ] %%在这种情况下,你的输入文件可能是错误的,可能是太大了,或者其他什么…
一般来说,重要的是要知道:
https://stackoverflow.com/questions/11710300
复制相似问题