Hi, I'm trying to build up a BufferedImage using its Graphics component, and
then print that image using a Printable. The problem is that some of my
operations on the graphics component seem to be lost, and when I print the
image, a lot of it is clipped off around the borders. The code below shows the
gist of what I'm doing.
// this method is in class A
foo(String text, Font font, B b, int x, int y) {
Graphics2D g2d = (Graphics2D) image.getGraphics();
g2d.setColor(Color.black); // this color gets lost when bar is called
g2d.setFont(font); // this font gets lost when bar is called
b.bar(text, x, y);
}
// this method is in class B
bar(String text, int x, int y) {
Graphics2D g2d = (Graphics2D) image.getGraphics();
g2d.drawString(text, x, y); // this does not get lost when the image is
printed
}
// this is the print method for the Printable, the image is passed to the
Printable
print(Graphics g, PageFormat pf, int pageIndex) {
if (pageIndex == 0) {
Graphics2D g2d = (Graphics2D)image.getGraphics();
g2d.translate(pf.getImageableX(), pf.getImageableY());
((Graphics2D)graphics).drawImage(image, null, 0, 0);
return Printable.PAGE_EXISTS;
} else {
return Printable.NO_SUCH_PAGE;
}
}
If I hardcode the color and font in the bar method, then the text actually
comes out at the printer, but if x < 80 or x > 500, it doesn't get printed;
same if y < 80 or y > 600 (these are approximate, I'm just estimating based on
what I printed and where it got cut off). This leaves about a 1 inch margin
around the printed text on the paper from the printer. Ultimately, I want to
generate a document image using j2d and send that to the printer. Any help is
greatly appreciated!
Thanks in advance!
[Message sent by forum member 'wtrpirate' (wtrpirate)]
http://forums.java.net/jive/thread.jspa?messageID=318909
===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff JAVA2D-INTEREST". For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".