Set the print properties to construct a new empty print request property set. Printrequestattributeset Pras = new Hashprintrequestattributeset ();p Ras.add (New Copies (3));//print copies, 3 copies// Sets the format of the printed data docflavor.byte_array. PNG MIME type = "Image/png", prints the data representation of the class name = "[B" (byte array) of the Docflavor. Docflavor flavor = Docflavor.byte_array. png;//Create print data doc MyDoc = new Simpledoc (New File (""), flavor, NULL); Find all eligible Print Services Lookupprintservices (flavor, Pras); Find the printservice that can print the specified docflavor. printservice[] Printservice = printservicelookup.lookupprintservices (flavor, Pras);//Match all the found printers to the printer you want, Find the printer you want Lookupprint p=new lookupprint (); Printservice Myprintservice = P.getprintservice ("Printname"); You can output the properties of the printer attributeset att = myprintservice.getattributes (); For (Attribute A:att.toarray ()) {System.out.println ("AttributeName:" +a.getname () + "AttributeValue:" + Att.get (A.getclass ()). ToString ()); } if (Myprintservice! = null) {Docprintjob job = MYPRINTSERVICE.CREATEPRINTJOB ();//Create document print job try {job.print (MyDoc, Pras);//Print Document} catch (Exception PE) { Pe.printstacktrace (); }}else{System.out.println ("No Printer Services found"); }
Java-implemented printer printing 2