| Author |
Printing HTML file
|
hamzeh hirzallah
Greenhorn
Joined: Sep 07, 2011
Posts: 4
|
|
hi
I have a problem in printing..
I want to print an HTML page on the printer, the file resides on the C:// and I want to send it to the printer,
when I do it i get the source code of the file which i don't want, i want a way to print the the HTML page as it is on the browser
how can I do that??
|
OCPJP 6 (96%)
|
 |
Rob Spoor
Sheriff
Joined: Oct 27, 2005
Posts: 19216
|
|
Welcome to the Ranch!
If supported, you can use java.awt.Desktop to print any file using its native program:
|
SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions How To Answer Questions
|
 |
hamzeh hirzallah
Greenhorn
Joined: Sep 07, 2011
Posts: 4
|
|
Thanks rop it worked for me, but i have a small question,
I want to print the file without the print dialog..
is this doable?
|
 |
Rob Spoor
Sheriff
Joined: Oct 27, 2005
Posts: 19216
|
|
Not with that method. It's possible using the Java printing libraries, but then you'll have to format the HTML page yourself. Perhaps you can use a third party library for that.
An alternative that's slightly easier if your HTML isn't too complex, is to use JEditorPane. That one can display simple HTML pages, as long as they are HTML 3.2 compatible. It also inherits a few print methods from JTextComponent. One of these takes a PrintService and only optionally shows a dialog. You can get a PrintService reference by calling PrintServiceLookup.lookupDefaultPrintService().
|
 |
 |
|
|
subject: Printing HTML file
|
|
|