File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Swing / AWT / SWT and the fly likes printing rtf from jEditorPane Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "printing rtf from jEditorPane" Watch "printing rtf from jEditorPane" New topic
Author

printing rtf from jEditorPane

Sancho Xavier
Greenhorn

Joined: Jan 11, 2010
Posts: 8
hello there,

I have developed an app that uses freemarker to load .rtf templates, insert text entered through a gui featuring numerous jTextFields into these templates, spit out a new .rtf file as well as load the new .rtf file into a jEditorPane (set to text/rtf) and finally print the jEditorPane. everything runs smoothly, save the printing part. the printed output does not match the contents of the jEditorPane (or the .rtf file itself) as closely as it should. for some reason the font is different and larger, and the spacing is off. i am not really certain what is going on here, but I have used this print class to enable the printing of a jEditorPane. if anyone has any clues as to why the printed version does not match the contents of the jEditorPane (it is rendered perfectly here...), i would be very greatful for your help.

Sancho
Stanislav Lapitsky
Ranch Hand

Joined: Dec 01, 2009
Posts: 53
There could be DPI difference between screen and printer device that's why font size is different. Not sure about this "the spacing is off" what does it mean?

You can also try to use something like this
http://java-sl.com/JEditorPanePrinter.html
to preview and see what's the difference with printed page.

may be the problem is difference in printed page width and JEditorPane width.

Regards,
Stas
Sancho Xavier
Greenhorn

Joined: Jan 11, 2010
Posts: 8
well i have since switched to a different printing class as seen here... and the problem is only slightly better. i am pretty sure that the problem lies in correctly specifying the margins, as when i print, the text is larger, the indents, spaces, etc are all out of whack, and text tends to be cut off in mid letter on the right side of the page. i have sent the rtf data to a jEditorPane with the size 504, 684 (which is an educated guess as to the size of a page with .5 inch margins...) and while the rtf data continues to show correctly in the jEditorPane, the printed version and the print preview are chopped. any help is greatly appreciated, printing in java seems so difficult!
Stanislav Lapitsky
Ranch Hand

Joined: Dec 01, 2009
Posts: 53
There is a guess about DPI difference. Could you measure your printed output? I guess it's ~33% bigger than necessary.
By default windows DPI is 96 but all printers are based to have 72 pixels.

You cna try to correct this but scale the printer graphics
g.scale(0.75, 0.75); // 72/96

Regards,
Stas
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: printing rtf from jEditorPane