title: Borderless printing
body: <p>I'm trying to write a photobooth program but I'm having a hard time making a borderless print. I'm very close but the image does not fill a 4" x 6" print. I would appreciate any tips on achieving a borderless print.</p>
  
  <p>Cheers!</p>
  
  <pre><code>    final BufferedImage img = ImageIO.read(new File(image));
  
      // Assuming that images are going to be 300 DPI
      PrinterResolution pr = new PrinterResolution(300, 300,
          PrinterResolution.DPI);
  
      PrintRequestAttributeSet pras = new HashPrintRequestAttributeSet();
      pras.add(pr);
  
      // Set print job so the image name shows (in the print queue)
      this.pj.setJobName(new File(image).getName());
  
      PageFormat pf = this.pj.getPageFormat(null);
      Paper paper = pf.getPaper();
      paper.setSize(4 * 72, 6 * 72);
      paper.setImageableArea(
          0.0, 0.0,
          paper.getWidth(), paper.getHeight()
      );
  
      if(img.getWidth(null) &gt; img.getHeight(null))
          pf.setOrientation(PageFormat.LANDSCAPE);
      else
          pf.setOrientation(PageFormat.PORTRAIT);
  
      pf.setPaper(paper);
  
      // Create the page
      this.pj.setPrintable(new Printable() {
          public int print(Graphics g, PageFormat pf, int i) throws 
              PrinterException {
              if (i != 0)
                  return NO_SUCH_PAGE;
  
              double width = img.getWidth(null);
              double height = img.getHeight(null);
  
              double w = Math.floor(pf.getImageableWidth() - 
                  pf.getImageableX()) / (width * 1.0);
  
              double h = Math.floor(pf.getImageableHeight() - 
                  pf.getImageableY()) / (height * 1.0);
  
              double scale = Math.min(w, h);
  
              Graphics2D g2 = (Graphics2D) g;
              g2.translate(0, 0);
              g2.scale(scale, scale);
              g2.drawImage(img, 0, 0, (int)width, (int)height, null);
  
              return PAGE_EXISTS;
          }
      }, this.pj.validatePage(pf));
  
      // Get number of copies
      int nCopies = SetPrintQuantity.getPrintQuantity(new File(image));
  
      // Print
      if(nCopies != 0)
          for(int i = 0; i &lt; nCopies; i++)
              this.pj.print(pras);
  
      System.out.println(nCopies + ((nCopies == 1) ? " copy" : " copies"));
  </code></pre>
  
  <p>this.pj = PrinterJob</p>