importjava.io.FileInputStream;
importjava.io.IOException;
importjavax.print.Doc;
importjavax.print.DocFlavor;
importjavax.print.DocPrintJob;
importjavax.print.PrintException;
importjavax.print.PrintService;
importjavax.print.PrintServiceLookup;
importjavax.print.SimpleDoc;
importjavax.print.attribute.HashPrintRequestAttributeSet;
importjavax.print.attribute.PrintRequestAttributeSet;
importjavax.print.attribute.standard.Copies;
publicclassPrintImage{
staticpublicvoidmain(Stringargs[])throwsException{
PrintRequestAttributeSetpras=newHashPrintRequestAttributeSet();
pras.add(newCopies(1));
PrintServicepss[]=PrintServiceLookup.lookupPrintServices(DocFlavor.INPUT_STREAM.GIF,pras);
if(pss.length==0)
thrownewRuntimeException("Noprinterservicesavailable.");
PrintServiceps=pss[0];
System.out.println("Printingto"+ps);
DocPrintJobjob=ps.createPrintJob();
FileInputStreamfin=newFileInputStream("YOurImageFileName.PNG");
Docdoc=newSimpleDoc(fin,DocFlavor.INPUT_STREAM.GIF,null);
job.print(doc,pras);
fin.close();
}
}
Java 打印图像直接打印
最新推荐文章于 2023-02-14 11:42:03 发布