Determining the Capabilities of a Print Service : Print Service « 2D Graphics GUI « Java






Determining the Capabilities of a Print Service

  

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;

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("filename.ps"));
    DocFlavor flavor = DocFlavor.INPUT_STREAM.GIF;
    StreamPrintServiceFactory[] factories = StreamPrintServiceFactory
        .lookupStreamPrintServiceFactories(flavor, DocFlavor.BYTE_ARRAY.POSTSCRIPT.getMimeType());

    StreamPrintService service = factories[0].getPrintService(fos);
    Attribute[] attrs = service.getAttributes().toArray();
    for (int j = 0; j < attrs.length; j++) {
      String attrName = attrs[j].getName();
      String attrValue = attrs[j].toString();
      System.out.println(attrName);
      System.out.println(attrValue);
    }
  }
}

   
    
  








Related examples in the same category

1.List Print Services
2.Using a Printing Service
3.Using a Streaming Printing Service
4.Discovering Available Print Services
5.Discovering Available Streaming Print Services
6.Use a factory to create a print service
7.Print a GIF image to any of the print services that support the GIF document flavor