• Post Reply Bookmark Topic Watch Topic
  • New Topic

Printing HTML With Java

 
Tony Alicea
Desperado
Sheriff
Posts: 3226
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I hope this is the right forum for asking this:
How does one write an HTML file to a printer using Java? Of course the HTML would have to be rendered just like in a browser.
Let's say that there are no GIFs or JPGs present; just straight HTML markup.
Thanks!
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The simplest approach would be to use a JEditorPane so that the HTML gets rendered correctly. And then you can call the print() method of the JEditorPane. Note that the formatting will be horrible as you haven't setup any of the margins on the page or anything like that. But like I Said, this is the simplest approach. I hate the printing API in JAVA so I have yet to really get in their and learn how to use it appropriately.
Here is the Java Trail on printing in JAVA. Hope that at least gets you somewhere.
 
Tony Alicea
Desperado
Sheriff
Posts: 3226
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks, Gregg...
I also hate the printing API in Java and it brings back "bad memories"...
And printing HTML has to be even more painful...
Thanks for the pointers and link. I had started to read about the JEditorPane or is it JEditorPain!?
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
JEditorPain!?
 
Tony Alicea
Desperado
Sheriff
Posts: 3226
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What Graphics object should I pass to the JEditorPane.print(Graphics g) (method actually inherited from JComponent)?
So far, nothing.
Not that I thought it would be easy!!
[ November 03, 2003: Message edited by: Tony Alicea ]
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just thought I would post some links that might be helpful -

http://developer.java.sun.com/developer/technicalArticles/Printing/Java2DPrinting/
http://developer.java.sun.com/developer/qow/archive/30/
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!