I am trying to print very simple HTML file using JAVA PrintServices API.
This is what I wrote for that -
public class WebTest {
public static void main(String args[]) throws Exception {
String filename = "C:/tmp/PrintTest.html";
PrintRequestAttributeSet pras = new HashPrintRequestAttributeSet();
DocFlavor flavor = DocFlavor.INPUT_STREAM.AUTOSENSE;
PrintService defaultService = PrintServiceLookup.lookupDefaultPrintService();
if (defaultService != null) {
DocPrintJob job = defaultService.createPrintJob();
FileInputStream fis = new FileInputStream(filename);
DocAttributeSet das = new HashDocAttributeSet();
Doc doc = new SimpleDoc(fis, flavor, das);
job.print(doc, pras);
}
System.exit(0);
}
However, my output file is not formatted properly - This is what I see in printed output -
<!DOCTYPE html>
<html>
<body>
<h2>Hello World.</h2>
</body>
</html>
I want to see Output as -
Hello World.
I also tried using Microsoft command for this - "C:\\Program Files\\Microsoft Office\\Office14\\msohtmed.exe\" /p C:/tmp/PrintTest.html
However its prompting me PRINT box which I want to get rid off.
My objective is just to get correctly printed output.
Please suggest suitable options.
I already referred other links, but couldn't find exact answer for what I am looking for.
Your help much appreciated.