title: Print Labels in a Label Printer using Java
body: <p>For the past 3 hours, 2 carbon inks and 2 rolls of Labels, I still can't print a single one. Been strugling for this for the whole day and still didn't figure anything out. It seems that everything is base on luck by the looks of it.</p>
  
  <pre><code>class MyPrintable implements Printable {
      public int print(Graphics g, PageFormat pf, int pageIndex) {
          if (pageIndex == 0) {
              Paper paper = new Paper();
  
              paper.setImageableArea(0, 0, 320, 115);
              paper.setSize(340, 128);
  
              pf.setPaper(paper);
  
              try {
                  BufferedImage read = ImageIO.read(new File("tmp/conv/foo.png"));
                  g.drawImage(read.getScaledInstance(220, 50, Image.SCALE_SMOOTH), 40, 10, null);
              } catch (IOException ex) {
  
              }
  
              return Printable.PAGE_EXISTS;
          }
          return Printable.NO_SUCH_PAGE;
      }
  }
  </code></pre>
  
  <p>I need to print a single barcode in ONE label. The label size is 9 cm wide and 3,4 cm tall. Which brings me to 340 pixels wide and 128 pixels tall. That's why I set the image size to those values.</p>
  
  <p>The problem is, when I tell the printer to print, it prints the barcode on the 8th label. It goes all the ways past the 7 first labels and print the things in between the 7th and 8th label ALL THE TIME. I have no idea why and I already tried with every possivel value. I set the size to 0px, the imageable size do 0px, the image scaled size to 0px and still it goes all the way to the 7th-8th label.</p>
  
  <p>Can someone please tell me what am I doing wrong?</p>