I use 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 programmatically reduce the size of the fields. No matter what I do, it always seems that there is no missing piece on the sides of the image (unless I delete the fields from the print dialog box, but, as I said, I want to remove them programmatically to automate the whole process).
David source share