Print HTML Files using Java without PRINT dialogue -


i trying print simple html file using java printservices api.

this wrote -

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, output file not formatted - see in printed output -

<!doctype html> <html>  <body>   <h2>hello world.</h2>  </body> </html> 

i want see output -

hello world. 

i tried using microsoft command - "c:\\program files\\microsoft office\\office14\\msohtmed.exe\" /p c:/tmp/printtest.html

however prompting me print box want rid off.

my objective correctly printed output.

please suggest suitable options.

i referred other links, couldn't find exact answer looking for.

your appreciated.

the html page should rendered before printing (calculate margins, arrange text on page, etc...). simplest way render , print html page using jeditorpane (in following snippet without additional formats, attributes , confirmation dialog):

public static void main(string[] args) throws printexception, ioexception, printerexception {     jeditorpane editorpane = new jeditorpane();     editorpane.seteditable(false);     url urltopage = new file("/home/me/temp/page.html").touri().tourl();     editorpane.setpage(urltopage);       editorpane.print(null, null, false, printservicelookup.lookupdefaultprintservice(), null, false); } 

Comments

Popular posts from this blog

javascript - Google App Script ContentService downloadAsFile not working -

javascript - Function overwritting -

php - Find a regex to take part of Email -