aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes Printing in Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Printing in "html/text" format" Watch "Printing in "html/text" format" New topic
Author

Printing in "html/text" format

kyle johnson
Greenhorn

Joined: Apr 06, 2010
Posts: 4
Hello, I'm working on a project and I want to print off a customer order. I want to be able to easily add sub headings wherever I want. It's also best to state here that I am quite new to Java.





My current solution is to add the generated text to a JEditorPane and print that using the following:


I'm just curious, am I using a ridiculous long winded method to get my intended result?

Thanks
Stanislav Lapitsky
Ranch Hand

Joined: Dec 01, 2009
Posts: 53
That's my attempt to print JEditorPane content paginated
http://java-sl.com/JEditorPanePrinter.html

if you need really WYSIWYG try also this
http://java-sl.com/Pagination_In_JEditorPane.html
Hope this helps.

Regards,
Stas
kyle johnson
Greenhorn

Joined: Apr 06, 2010
Posts: 4
Thanks, those are two really good examples.


In regards to those, is it possible to print a JEditorPane without it being added to a JFrame?

Later in my program I want to be able to print a JEditorPane without displaying it in a UI, however I found that it would only print once it had been added to a JFrame and the pack() method had been called.


Best regards,
Kyle
Stanislav Lapitsky
Ranch Hand

Joined: Dec 01, 2009
Posts: 53
You should set size for the JEditorPane to let it layout. Also some changes of content layout are done only during paint (e.g. components of HTML location).

You can try to use invisible frame. Just create it and pack() but set location out of screen.

Regards,
Stas
kyle johnson
Greenhorn

Joined: Apr 06, 2010
Posts: 4
Thanks for the reply,

Yeah that's what iv ended up doing. Thanks for your help
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Printing in "html/text" format