A piece of data is to be sent to the printer, and it consists of an image and some text on it. I call the Graphic2D
drawImage()
, passing to it a BufferedImage
which the function scales down to fit the printer imageable area, and also call the drawString()
serveral times. The problem is, some of the text printed "behind" the image and hence invisible!
Since drawImage()
process includes a time taking scale-down, and I have no access to the PageFormat and the imageable area before I'm inside the print()
, the drawString()
s are taking place before the drawImage()
.
Maybe the solution is an ImageObserver, but I don't know how it can help in this case. Please help!
edit: The problem looks like this:
public int print(Graphics graphics, PageFormat pageFormat, int pageIndex) throws PrinterException
final Graphics2D g = (Graphics2D) graphics;
g.translate(pageFormat.getImageableX(), pageFormat.getImageableY());
int width = (int) pageFormat.getImageableWidth();
int height = (int) pageFormat.getImageableHeight() / 2 - 10;
g.drawImage(img, 0, 0, width, height, null);
g.drawString("Some text 1", 20, 20);
for (int i = 0; i < someList.size(); i++)
g.drawString("Some text 2", 20, 40 + i * 15); // This is overshadowed by the image...!
.
.
.
}