【发布时间】:2016-08-14 15:32:46
【问题描述】:
我正在尝试打印 PDF 文档。
我可以看到打印机队列中的作业,然后我看到它消失了,就像打印机完成了它的作业一样。
但问题是什么都没有打印。 我无法弄清楚我的代码有什么问题。
PrintService[] printServices = PrintServiceLookup.lookupPrintServices(null,null);
PrintService service = null;
for (String imprimante : listImprimantes){
for( PrintService printService : printServices ) {
Attribute[] attrs = printService.getAttributes().toArray();
for (int j=0; j<attrs.length; j++) {
String attrName = attrs[j].getName();
String attrValue = attrs[j].toString();
if (attrName.equals("printer-info")){
if (attrValue.equals(imprimante)){
service = printService;
DocFlavor[] flavors = service.getSupportedDocFlavors();
break;
}
}
}
}
}
InputStream fi = new ByteArrayInputStream(baos.toByteArray());
DocFlavor flavor = DocFlavor.INPUT_STREAM.AUTOSENSE;
DocPrintJob printJob = service.createPrintJob();
Doc doc = new SimpleDoc(fi, flavor, null);
try {
if (doc != null) {
printJob.print(doc, null);
}
}
catch (PrintException e1) {
log.debug(e1.getMessage());
}
如果有人可以帮助我...
【问题讨论】:
-
你有没有想过这个问题?我也有同样的问题...
-
不,我没有。问题仍在进行中
-
我面临着和你一样的情况(Windows 8)java 8,我用 apache PDF 框尝试了@teemoo 答案,但它只适用于 PDF 格式。
-
我也遇到了同样的问题,请问有解决办法吗?