Link to home
Start Free TrialLog in
Avatar of cen7mjs
cen7mjs

asked on

Printing the contents of a JEditorPane/HTML

I have two scenarios where I could need to print the contents of a html page.
In the first case I am using the HTMLEditorKit to display a HTML page through a JEditorPane - how do I print the contents?
And the second, I have managed to send the `raw` contents of a html file to the printer without using the JEditorPane, but all the source tags are also displayed with no formatting - is there a way to preformat the code before sending it to the printer?? I am already trying to put this through the JEditorPane as I thought this may provide a way around this, but now have the problem of printing from there.
Any help is much appreciated,
Thanks,
Mike Smith
ASKER CERTIFIED SOLUTION
Avatar of bobbit31
bobbit31
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of kylar
kylar

Wow, just stole my code and didn't even credit me. Bad form!

(Printing HTML in Editor Pane:)
https://www.experts-exchange.com/jsp/qShow.jsp?ta=java&qid=20249747

https://www.experts-exchange.com/jsp/qShow.jsp?ta=java&qid=20149088

Printing JTable (Just in case).
https://www.experts-exchange.com/jsp/qShow.jsp?ta=java&qid=20136146

Cheers,
Kylar
> Wow, just stole my code and didn't even credit me

sorry, i copied it a long time ago to my local resources and didn't paste author/location information (don't tell me you've never done that)... so didn't know who to credit to or even where i got it from.

(note made in my local file)

:)

Kylar
Avatar of cen7mjs

ASKER

Thanks guys,

I have managaged to solve the problem now although the way i have done it slightly different as i don`t have an actual URL to pass in - instead i have a String of html code which is place in a StringBuffer and passed into the HTMLEditorKit and used to create the JEditor Pane in the first place. I have then used a class similiar to the one above (PrintableEditorPane) extending JeditorPane to create my reference to my jEditorPane and then pretty much as above.

So... i can`t really split points, but will award points to the first answer i recieved.

Cheers,
Mike