Discovering Available Print Services - Java 2D Graphics

Java examples for 2D Graphics:Print

Description

Discovering Available Print Services

Demo Code

import javax.print.DocFlavor;
import javax.print.PrintService;
import javax.print.PrintServiceLookup;
import javax.print.attribute.AttributeSet;
import javax.print.attribute.HashAttributeSet;
import javax.print.attribute.standard.ColorSupported;
import javax.print.attribute.standard.PrinterName;

public class Main {

  public void main(String[] argv) {
    PrintService[] services = PrintServiceLookup
        .lookupPrintServices(null, null);

    PrintService service = PrintServiceLookup.lookupDefaultPrintService();

    // Find all services that can support GIF
    services = PrintServiceLookup.lookupPrintServices(
        DocFlavor.INPUT_STREAM.GIF, null);

    // Find a particular service by name
    AttributeSet aset = new HashAttributeSet();
    aset.add(new PrinterName("HP LaserJet 6MP PS", null));
    services = PrintServiceLookup.lookupPrintServices(null, aset);

    // Find all services that support a set of print job capabilities;
    // in this case, color
    aset = new HashAttributeSet();
    aset.add(ColorSupported.SUPPORTED);
    services = PrintServiceLookup.lookupPrintServices(null, aset);
  }/*from ww  w.j a v a2s.c  o m*/
}

Related Tutorials