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 31 32 33 34 35 36 37 38 39 40 41 42
|
try {
PrintRequestAttributeSet pras = new HashPrintRequestAttributeSet();
pras.add(new Copies(1));
PrintService pss[] = PrintServiceLookup.lookupPrintServices(DocFlavor.INPUT_STREAM.PNG, pras);
for (PrintService ps : pss) {
}
if (pss.length == 0)
throw new RuntimeException("No printer services available.");
PrinterJob pp=PrinterJob.getPrinterJob();
if (pp.printDialog()) {
try {
pp.print();
} catch (PrinterException ex) {
Logger.getLogger(Audio.class.getName()).log(Level.SEVERE, null, ex);
}
}
PrintService ps = pp.getPrintService();
System.out.println("Printing to yy" + ps);
DocPrintJob job = ps.createPrintJob();
FileInputStream fin = new FileInputStream("s.png");
Doc doc = new SimpleDoc(fin, DocFlavor.INPUT_STREAM.PNG, null);
job.print(doc, pras);
fin.close();
} catch (IOException ie) {
ie.printStackTrace();
} catch (PrintException pe) {
pe.printStackTrace();
} |
Partager