Home » Desktop Java » print » Discover Streaming Print Services

About Ilias Tsagklis

Ilias Tsagklis
Ilias is a software developer turned online entrepreneur. He is co-founder and Executive Editor at Java Code Geeks.

Discover Streaming Print Services

With this example we shall show you how to discover streaming print services in a Java Desktop Application. You will find this particularly useful when you want to create and handle print jobs from you application.

Discovering streaming print services is very easy as it requires that you :

  • Use StreamPrintServiceFactory.lookupStreamPrintServiceFactories(null, null) to locates factories for print services that can be used with a print.
  • Use StreamPrintServiceFactory.lookupStreamPrintServiceFactories to find all streaming factories that support particular input

Let’s see the code snippet that follows:

package com.javacodegeeks.snippets.desktop;

import javax.print.DocFlavor;
import javax.print.StreamPrintServiceFactory;

public class DiscoverStreamingPrintServices {

	public static void main(String[] args) {

		// locates factories for print services that can be used with a print
		// job to output a stream of data in the format specified by flavor
		// with null no constraints are used
		StreamPrintServiceFactory[] factories = StreamPrintServiceFactory
				.lookupStreamPrintServiceFactories(null, null);

		System.out.println("Streaming Printer Factories found:");
		printFactories(factories);

		// find all streaming factories that support particular input
		// formats (e.g. JPEG and Postscript)
		factories = StreamPrintServiceFactory.lookupStreamPrintServiceFactories(
		    DocFlavor.INPUT_STREAM.GIF,
		    DocFlavor.BYTE_ARRAY.POSTSCRIPT.getMimeType());

		System.out.println("Streaming Printer Factories found (with JPEG/Postscript):");
		printFactories(factories);

	}

	private static void printFactories(StreamPrintServiceFactory[] factories) {
		if (factories!=null && factories.length>0) {
			for (int i = 0; i < factories.length; i++) {
				System.out.println("t" + factories[i].getClass().getCanonicalName());
			}
		}
	}

}

Output:

Streaming Printer Factories found:
	sun.print.PSStreamPrinterFactory
Streaming Printer Factories found (with JPEG/Postscript):
	sun.print.PSStreamPrinterFactory

 
This was an example on discovering Streaming Print Services.

(No Ratings Yet)
Start the discussion Views Tweet it!

Do you want to know how to develop your skillset to become a Java Rockstar?

Subscribe to our newsletter to start Rocking right now!

To get you started we give you our best selling eBooks for FREE!

 

1. JPA Mini Book

2. JVM Troubleshooting Guide

3. JUnit Tutorial for Unit Testing

4. Java Annotations Tutorial

5. Java Interview Questions

6. Spring Interview Questions

7. Android UI Design

 

and many more ....

 

Receive Java & Developer job alerts in your Area

 

Leave a Reply

avatar
  Subscribe  
Notify of