I'm trying to print an html file directly to the default printer without showing print dialog to the user.
I just got the below code from some online tutorials and it worked well for the PNG file.
import javax.print.*;
import javax.print.attribute.*;
import java.io.*;
public class Printing {
public static void main(String args[]) throws Exception {
String filename = args[0];
PrintRequestAttributeSet pras =
new HashPrintRequestAttributeSet();
DocFlavor flavor = DocFlavor.INPUT_STREAM.PNG;
PrintService printService[] =
PrintServiceLookup.lookupPrintServices(flavor, pras);
PrintService defaultService =
PrintServiceLookup.lookupDefaultPrintService();
PrintService service = ServiceUI.printDialog(null, 200, 200, printService, defaultService, flavor, pras);
if (service != null) {
DocPrintJob job = service.createPrintJob();
FileInputStream fis = new FileInputStream(filename);
DocAttributeSet das = new HashDocAttributeSet();
Doc doc = new SimpleDoc(fis, flavor, das);
job.print(doc, pras);
Thread.sleep(10000);
}
System.exit(0);
}
}
I would like to change DocFlavor flavor = DocFlavor.INPUT_STREAM.PNG;
to DocFlavor flavor = DocFlavor.INPUT_STREAM.<some html format>;
Please suggest which format would be appropriate to use here ?
and please suggest how to avoid print dialog pop up while running this code. ?
Thanks in Advance Sandy