Java by API/javax.print.event/PrintJobListener

Материал из Java эксперт
Версия от 14:48, 31 мая 2010; Admin (обсуждение | вклад) (1 версия)
(разн.) ← Предыдущая | Текущая версия (разн.) | Следующая → (разн.)
Перейти к: навигация, поиск

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) {
  }
}