Java examples for 2D Graphics:Print
Discovering Available Streaming Print Services
import java.io.BufferedOutputStream; import java.io.FileOutputStream; import java.io.OutputStream; import javax.print.DocFlavor; import javax.print.StreamPrintService; import javax.print.StreamPrintServiceFactory; public class Main { public static void main(String[] argv) throws Exception{ // Look up all streaming factories StreamPrintServiceFactory[] factories = StreamPrintServiceFactory .lookupStreamPrintServiceFactories(null, null); // Find all streaming factories that support particular input formats; factories = StreamPrintServiceFactory.lookupStreamPrintServiceFactories( DocFlavor.INPUT_STREAM.GIF, DocFlavor.BYTE_ARRAY.POSTSCRIPT.getMimeType()); // Use a factory to create a print service. OutputStream fos = new BufferedOutputStream(new FileOutputStream( "outfile.ps")); StreamPrintService service = factories[0].getPrintService(fos); }/* ww w . j ava 2s .com*/ }