implements PrintJobListener : PrintJobListener « javax.print.event « Java by API






implements PrintJobListener

  

import java.io.BufferedOutputStream;
import java.io.FileOutputStream;
import java.io.OutputStream;

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("filename.ps"));
    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) {
    System.out.println("printDataTransferCompleted");
  }

  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