Im using PrinterJob object in order to print my Bufferedimage, I have a BufferedImage which I proccess and send it to Printer job with Paper Format etc, and I cant make it fittable to my card printer. when i save it to my hard-disk and print via windows printing manager it printing very good on my card printer but with PrinterJob it came out too big and not fittable for a card
the size of the card is 86X54mm and the size of my buffered image is 1300x816px The Code :
PrinterJob printjob = PrinterJob.getPrinterJob();
printjob.setJobName("CardPrint");
Printable printable = new Printable() {
public int print(Graphics pg, PageFormat pf, int pageNum) {
if (pageNum > 0) {
return Printable.NO_SUCH_PAGE;
}
JLayeredPane j1 = new JLayeredPane();
Dimension size = j1.getSize();
j1.print(bi.getGraphics());
Graphics2D g2 = (Graphics2D) pg;
g2.translate(pf.getImageableX(), pf.getImageableY());
g2.drawImage(bi, 0, 0, (int) pf.getWidth(), (int) pf.getHeight(), null);
return Printable.PAGE_EXISTS;
}
};
Paper paper = new Paper();
paper.setImageableArea(0, 0, 0, 0);
paper.setSize(1.15, 0.72);
PageFormat format = new PageFormat();
format.setPaper(paper);
printjob.setPrintable(printable, format);
try {
printjob.printDialog();
printjob.print();
} catch (Exception eee){
System.out.println("NO PAGE FOUND."+eee.toString());
}
I found out that paper.setSize(1.15, 0.7); is in inch (http://docs.oracle.com/javase/1.5.0/docs/api/java/awt/print/Paper.html) paper.setImageableArea(0, 0, 0, 0); and i dont know about this setImageableArea.
does any one has clue about the current sizes, do i made a mistake calculating ? thanks.