Printing the Java 1.4 Way
import java.io.FileInputStream;
import javax.print.Doc;
import javax.print.DocFlavor;
import javax.print.DocPrintJob;
import javax.print.PrintService;
import javax.print.PrintServiceLookup;
import javax.print.SimpleDoc;
import javax.print.attribute.DocAttributeSet;
import javax.print.attribute.HashDocAttributeSet;
import javax.print.attribute.HashPrintRequestAttributeSet;
import javax.print.attribute.PrintRequestAttributeSet;
import javax.print.event.PrintJobAdapter;
import javax.print.event.PrintJobEvent;
import javax.print.event.PrintJobListener;
public class PrintingOneFour {
public static void main(String args[]) throws Exception {
String filename = args[0];
DocFlavor flavor = DocFlavor.INPUT_STREAM.GIF;
PrintService printService = PrintServiceLookup
.lookupDefaultPrintService();
DocPrintJob job = printService.createPrintJob();
PrintJobListener listener = new PrintJobAdapter() {
public void printDataTransferCompleted(PrintJobEvent e) {
System.out.println("Good-bye");
System.exit(0);
}
};
job.addPrintJobListener(listener);
PrintRequestAttributeSet pras = new HashPrintRequestAttributeSet();
FileInputStream fis = new FileInputStream(filename);
DocAttributeSet das = new HashDocAttributeSet();
Doc doc = new SimpleDoc(fis, flavor, das);
job.print(doc, pras);
Thread.sleep(10000);
}
}
Related examples in the same category