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
|
PrintRequestAttributeSet pras = new HashPrintRequestAttributeSet();
DocFlavor flavor = DocFlavor.INPUT_STREAM.AUTOSENSE;
// lister les imprimantes qui supportent ce flavor
@SuppressWarnings("unused")
PrintService printService[] = PrintServiceLookup
.lookupPrintServices(flavor, pras);
PrintService service = PrintServiceLookup
.lookupDefaultPrintService();
// choix de l'imprimante
//PrintService service = ServiceUI.printDialog(null, 200, 200,
// printService, defaultService, flavor, pras);
if (service != null) {
System.out.println(service.getName());
DocPrintJob job = service.createPrintJob();
System.out.println(job.getPrintService().getName());
try {
FileInputStream fis = new FileInputStream("C://etiquette/etiquette");
DocAttributeSet das = new HashDocAttributeSet();
Doc doc = new SimpleDoc(fis, flavor, das);
// lancement de l'impression
job.print(doc, pras);
} catch (PrintException ex) {
} catch (FileNotFoundException ex) {
}
} |
Partager