Listening for Print Job Status Changes : Print Job « 2D Graphics GUI « Java

Listening for Print Job Status Changes


import javax.print.DocFlavor;
import javax.print.DocPrintJob;
import javax.print.StreamPrintService;
import javax.print.StreamPrintServiceFactory;
import javax.print.event.PrintJobEvent;
import javax.print.event.PrintJobListener;

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

    StreamPrintService service = factories[0].getPrintService(fos);

    DocPrintJob job = service.createPrintJob();
    job.addPrintJobListener(new MyPrintJobListener());

class MyPrintJobListener implements PrintJobListener {
  public void printDataTransferCompleted(PrintJobEvent pje) {

  public void printJobCanceled(PrintJobEvent pje) {
    System.out.println("The print job was cancelled"); 

  public void printJobCompleted(PrintJobEvent pje) {
    System.out.println("The print job was completed"); 

  public void printJobFailed(PrintJobEvent pje) {
    System.out.println("The print job has failed");

  public void printJobNoMoreEvents(PrintJobEvent pje) {

  public void printJobRequiresAttention(PrintJobEvent pje) {


Related examples in the same category

1.Cancelling a Print Job
2.Determining Print Job Capabilities Supported by a Print Service
3.Getting the Default Value of a Print Job Capability
4.Getting the Possible Values for a Print Job Capability
5.Setting the Orientation of a Print Job -- Portrait or Landscape
6.Setting the Number of Copies of a Print Job
7.Listening for Print Job Attribute Changes
8.Determining When a Print Job Has Finished
9.How to print 2D graphicsHow to print 2D graphics