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