Meaningless Drivel is fun!*
The moose likes I/O and Streams and the fly likes JavaX Printing of HTML Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "JavaX Printing of HTML" Watch "JavaX Printing of HTML" New topic
Author

JavaX Printing of HTML

merwin pinto
Ranch Hand

Joined: Feb 16, 2005
Posts: 39
Hi,
I am trying to print HTML data using the javax.print package
Now, i am having problem defining the 'DocFlavor' ...... not sure what to give

here is the code
=============================
String is="<html> <body> <table> <tr> any Print data</tr> </table> </body></html>";
DocFlavor flavor = DocFlavor.BYTE_ARRAY.AUTOSENSE;
PrintService service = PrintServiceLookup.lookupDefaultPrintService();
DocPrintJob job = service.createPrintJob();
Doc doc = new SimpleDoc(is.getBytes(), flavor, null);
job.print(doc, null);

===================================

here it will print every thing including HTML
if i change the DocFlavor to DocFlavor.BYTE_ARRAY.TEXT.HTML.HOST
it throws a invalid flavor exception.....

It would be great if any one could guid me to print html
Thanks a lot
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8927
    
    9

I used javax.print briefly a few months ago, and I seem to remember that the DocFlavor one uses is determined by what the printer will handle, not what the document is, so AUTOSENSE is the one I went with.
The "flavor exception" is thrown because the printer can't render HTML directly. AUTOSENSE works because the printer engine will figure out what the printer can handle and do the translation.
When you use AUTOSENSE do you get the rendered HTML or the source?
[ April 05, 2006: Message edited by: Joe Ess ]

"blabbing like a narcissistic fool with a superiority complex" ~ N.A.
[How To Ask Questions On JavaRanch]
merwin pinto
Ranch Hand

Joined: Feb 16, 2005
Posts: 39
When i use AUTOSENSE ...... it just prints the source , and is not able to resolve HTML
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8927
    
    9

That's what I expected. I would expect you would need to render the HTML using an editor pane and print that if you don't just want to print the source.
merwin pinto
Ranch Hand

Joined: Feb 16, 2005
Posts: 39
I guess i will do that ... Thanks a lot
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JavaX Printing of HTML