Hi

I had the same problem with default paper with my software for
printing labels. Finally I discovered that using the Book class
can help. When I used the standard way the paper
always changed to some default size and the imaginable area 
was also wrong.

greetings from Poland

here is my class for printing images with Book usage (1.5 JRE):

public class ImagePrinter implements Printable {

  private Image image;

  public static void printImage(Image aImage) throws PrinterException {
    new ImagePrinter(aImage).print();
  }

  public ImagePrinter(Image aImage) {
    image = aImage;
  }

  public void print() throws PrinterException {
    PrinterJob pPrinterJob = PrinterJob.getPrinterJob();
    if (pPrinterJob.printDialog()) {
      PageFormat pPageFormat = pPrinterJob.defaultPage();
      Paper pPaper = pPageFormat.getPaper();
      pPaper.setImageableArea(1.0, 1.0, pPaper.getWidth() - 2.0, 
pPaper.getHeight() - 2.0);
      pPageFormat.setPaper(pPaper);
      pPageFormat = pPrinterJob.pageDialog(pPageFormat);
      Book pBook = new Book();
      pBook.append(this, pPageFormat);
      pPrinterJob.setPageable(pBook);
      pPrinterJob.print();
    }
  }

  public int print(Graphics g, PageFormat aPageFormat, int aPageIndex) {

    if (aPageIndex > 0) {
      return NO_SUCH_PAGE;
    }

    Graphics2D g2d = (Graphics2D) g;
    AffineTransform pOrigTransform = g2d.getTransform();

    g2d.translate(aPageFormat.getImageableX(), aPageFormat.getImageableY());
    g2d.drawImage(image, 0, 0, null);

    g2d.setTransform(pOrigTransform);
    return PAGE_EXISTS;
  }
}
[Message sent by forum member 'alladyn' (alladyn)]

http://forums.java.net/jive/thread.jspa?messageID=247796

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