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.
may be the problem is difference in printed page width and JEditorPane width.
Joined: Jan 11, 2010
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!
Joined: Dec 01, 2009
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