Determining Print Job Capabilities Supported by a Print Service - Java 2D Graphics

Java examples for 2D Graphics:Print

Description

Determining Print Job Capabilities Supported by a Print Service

Demo Code

import java.lang.reflect.Array;

import javax.print.PrintService;
import javax.print.attribute.Attribute;

public class Main {

  public void main(String[] argv) {
    PrintService service = null;/*  www.j a va  2  s  .  c o  m*/
    Class[] cats = service.getSupportedAttributeCategories();
    for (int j = 0; j < cats.length; j++) {
      Attribute attr = (Attribute) service.getDefaultAttributeValue(cats[j]);

      if (attr != null) {
        // Get attribute name and values
        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 Tutorials