Java-implemented printer printing 2

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.