Java print : rien ne sort l'imprimante.
Bonjour,
Je cherche à imprimer un fichier texte sur mon imprimante réseau (qui s'appelle 'Commercial') avec java.
J'ai fait ce code :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
| DocFlavor flavor = DocFlavor.INPUT_STREAM.AUTOSENSE;
PrintService[] printServices = PrintServiceLookup.lookupPrintServices(flavor,new HashPrintRequestAttributeSet());
PrintService service = null;
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-name")){
if (attrValue.equals("Commercial")){
service = printService;
}
}
}
}
try {
if (service != null){
FileInputStream fis = new FileInputStream("c:/mytxt.txt");
Doc pdfDoc = new SimpleDoc(fis, DocFlavor.INPUT_STREAM.AUTOSENSE, null);
DocPrintJob printJob = service.createPrintJob();
printJob.print(pdfDoc, new HashPrintRequestAttributeSet());
fis.close();
}
}
catch (Exception e1) {
System.out.println(e1.getMessage());
} |
Ca marche bien sous linux, mais sous windows je vois le fichier dans la file d attente de l'imprimante, puis il disparait comme s'il s'était imprimé. Mais rien ne sort de l'imprimante.
J'aurais voulu savoir si le probleme pouvait venir de mon code ou si c'etait forcément un problème de driver.
Merci pour vos réponses.