The clipping is because the imageable area of the paper may be less than the physical size of the paper. You need to get the imageable area from the PageFormat and then scale your rendering (ie the final image) to fit. You can also control this by specifying the imageable area in the PageFormat but you'll need to use the javax.print
APIs to find out what is the hard liimit for the device
See http://java.sun.com/javase/6/docs/api/javax/print/attribute/standard/MediaPrintableArea.html

But
>I'm trying to build up a BufferedImage using its Graphics component, and then print that image using a Printable
Why? As in I don't know why you aren't rendering directly to the printer ?

If you do what you are doing you will get blocky output, unless you create a very large image and scale it to printer resolutions. Even then it means you won't get printer fonts etc.

So I suspect your approach is costing you in
- output quality
- memory used
- performance

-phil.

[EMAIL PROTECTED] wrote:
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".

===========================================================================
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".

Reply via email to