我正在嘗試打印PDF文檔。
我可以在打印機隊列中看到作業,然後看到它消失,就像打印機已完成作業一樣。PDF Java打印:在打印機作業隊列中發送的作業,但沒有打印
但問題是沒有打印。 我找不出在我的代碼中有什麼問題。
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());
}
如果有人可以幫助我在此...
你有沒有想過這個?我有同樣的問題... –
不,我沒有。問題仍在進行中 – user1260928