Making a Graphics object like the one I get when printing
posted 13 years ago
I'm using the java.awt.print API to print a small string. I implement Printable.print, which receives a reference to a Graphics object. I get the FontMetrics object from the Graphics object and use it's bytesWidth() method to determine the length of the string when rendered with the current font type and size. I would like to get the value returned from bytesWidth() prior to the call to Printable.Print(), but as I mentioned, the bytesWidth() method is from a FontMetrics object which is from a Graphics object which is passed to Printable.print(). Is there any way to make a Graphics object prior to the call to Printable.print() that is equivalent to the one handed to Printable.print() that I can use to determine the string's width? I need this in order to set the page orientation prior to Printable.print() being called (setting the orientation in print() doesn't work).