I have struggled with this problem for long time and couldn't find any answer. My problem is, that I have some text, which I would like to print using java's PrinterJob, but I want to be able to show the user how many pages will be printed in the print dialog (if I do not specify the number, 9999 will show up as the number of pages).
It's OK with images, custom shapes, etc. because I can simply calculate the number of pages for the content using given PageFormat. BUT! with text content I can't calculate the size of the text without the Graphics object or the FontRenderContext!
So in practice that means I can calculate the text size only in the print method of the Printable interface using given Graphics and getFontMetrics method. Am I right?
One way would be to create Images from my content and then printing the images, but I don't want that, because for my purposes I need to draw the text directly into Graphics object in my print method.
So tell me guys am I stupid or is this not doable in Java? I suppose the first option is correct.