I am using this code to print on paper:
//Overriden from printable interface
public int print(Graphics g, PageFormat pageFormat, int pageIndex)
throws PrinterException {
if (pageIndex != 0) {
return Printable.NO_SUCH_PAGE;
}
Paper a4 = new Paper();
a4.setImageableArea(0, 0, a4.getWidth(), a4.getHeight());
pageFormat.setPaper(a4);
pageFormat.setOrientation(PageFormat.PORTRAIT);
Graphics2D g2d = (Graphics2D)g;
//g2d.translate(pageFormat.getImageableX(), pageFormat.getImageableY());
this.setDoubleBuffered(false);
panel.print(g2d);
JOptionPane.showMessageDialog(null, new ImageIcon(image));
this.setDoubleBuffered(true);
return Printable.PAGE_EXISTS;
}
I am trying to reduce the size of the margins programmatically. Whatever I do, there always seems to be a large missing chunk from the image's sides (Unless I remove the margins from the print dialog - but as I said, I want to remove them programatically to automate the whole process).