Determining Print Job Capabilities Supported by a Print Service : Print Job « 2D Graphics GUI « Java

Determining Print Job Capabilities Supported by a Print Service

import java.lang.reflect.Array;

import javax.print.DocFlavor;
import javax.print.StreamPrintService;
import javax.print.StreamPrintServiceFactory;
import javax.print.attribute.Attribute;

public class Main {
  public static void main(String[] argv) throws Exception {
    OutputStream fos = new BufferedOutputStream(new FileOutputStream(""));
    DocFlavor flavor = DocFlavor.INPUT_STREAM.GIF;
    StreamPrintServiceFactory[] factories = StreamPrintServiceFactory
        .lookupStreamPrintServiceFactories(flavor, DocFlavor.BYTE_ARRAY.POSTSCRIPT.getMimeType());

    StreamPrintService service = factories[0].getPrintService(fos);
    Class[] cats = service.getSupportedAttributeCategories();
    for (int j = 0; j < cats.length; j++) {
      Attribute attr = (Attribute) service.getDefaultAttributeValue(cats[j]);

      if (attr != null) {
        String attrName = attr.getName();
        String attrValue = attr.toString();

        Object o = service.getSupportedAttributeValues(attr.getCategory(), null, null);
        if (o.getClass().isArray()) {
          for (int k = 0; k < Array.getLength(o); k++) {
            Object o2 = Array.get(o, k);


Related examples in the same category

1.Cancelling a Print Job
2.Getting the Default Value of a Print Job Capability
3.Getting the Possible Values for a Print Job Capability
4.Setting the Orientation of a Print Job -- Portrait or Landscape
5.Setting the Number of Copies of a Print Job
6.Listening for Print Job Status Changes
7.Listening for Print Job Attribute Changes
8.Determining When a Print Job Has Finished
9.How to print 2D graphicsHow to print 2D graphics