Get the Possible Values for a Print Job Capability in Java

Description

The following code shows how to get the Possible Values for a Print Job Capability.

Example


//from www. j  a  va2s  .c  o  m
import java.io.BufferedOutputStream;
import java.io.FileOutputStream;
import java.io.OutputStream;
import java.lang.reflect.Array;

import javax.print.DocFlavor;
import javax.print.StreamPrintService;
import javax.print.StreamPrintServiceFactory;
import javax.print.attribute.standard.OrientationRequested;

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

    StreamPrintService service = factories[0].getPrintService(fos);
    Class category = OrientationRequested.class;
    Object o = service.getSupportedAttributeValues(category, null, null);
    if (o == null) {
      System.out.println("Attribute is not supported");
    } else if (o.getClass() == category) {
      System.out.println("irrelevant");
    } else if (o.getClass().isArray()) {
      System.out.println("array"); 
      for (int i = 0; i < Array.getLength(o); i++) {
        Object v = Array.get(o, i);
        System.out.println(v);
      }
    } 
  }
}




















Home »
  Java Tutorial »
    Graphics »




Animation
BufferedImage
Color
Font
Gradient
Graphics Settings
Image
Mouse Draw
Print
Shape
Text
Transform