This discussion is archived
0 Replies Latest reply: Jun 16, 2011 12:40 PM by 863246 RSS

java.awt.print API and 4x6 prints

863246 Newbie
Currently Being Moderated
Hello, I've been trying for days now to get a Sony UP-DR200 printer to print a picture in 4x6" size, the printer reports "paper pixels" of 2048x1382 for print size of 4x6", however if I print an image with this resolution the result is always trimmed at the bottom of the print. I've tried many resolutions now, but nothing is working.

The question is: what other considerations do I need to take in order to print images in sizes of 4x6"? Here's the actual code I'm using:

public class TestPrinting implements Printable {

public int print(Graphics g, PageFormat pf, int page) throws PrinterException {

if (page > 0) {
return NO_SUCH_PAGE;

BufferedImage image = null;

try {
image =

Graphics2D g2d = (Graphics2D)g;
g2d.translate(pf.getImageableX(), pf.getImageableY());

AffineTransform transform = new AffineTransform();
transform.translate(0, 0);

double widthScale = pf.getWidth()/image.getWidth();
double heightScale= pf.getHeight()/1977;

/** Scale the image so if fits in the paper */
transform.scale(widthScale, heightScale);
g2d.drawRenderedImage(image, transform);
} catch (Exception e) {


public static void main(String[] args) throws Exception {
Printable p = new TestPrinting();
PrinterJob printerJob = PrinterJob.getPrinterJob();
PageFormat pf = new PageFormat();

/** Here I choose no margins so imageableX and Y are 0, and paper size 4x6" */
pf = printerJob.pageDialog(pf);

printerJob.setPrintable(p, pf);

Thanks in advance,
Edgar Merino

Edited by: 860243 on 16/06/2011 12:40 PM


  • Correct Answers - 10 points
  • Helpful Answers - 5 points