Field Reduction - Java Printing

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).

+4
source share
1 answer

The US letter , for example, measures 8½ x 11 inches. At 72 dpi, it's 612 x 792.

On a typical printer having paper of this size, the PageFormat object reports the following area.

 System.out.println(pf.getImageableX() + " " + pf.getImageableY() + " " + pf.getImageableWidth() + " " + pf.getImageableHeight()); 
  18.0 18.0 576.0 734.0
 18.0 18.0 576.0 734.0

Few consumer printers are full-bleed , so the attractive area is smaller than the physical size of the paper suggests. In fact, the printer cannot place ink where it cannot print.

+2
source

All Articles