1

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.

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;
    }
}

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.

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.

Can someone please tell me what am I doing wrong?

renatojf
  • 734
  • 2
  • 11
  • 29
  • 4
    Don't change the Paper in the print method, it will,have no effect, Java has already setup the paper before this method is called. Take a look at [thid question/answer](http://stackoverflow.com/questions/11803741/printing-in-java-to-label-printer/11805237#11805237) for an example – MadProgrammer Apr 15 '13 at 20:21
  • Thank you MadProgrammer! Thank you! Thank you! Thank you! that helped a lot! – renatojf Apr 15 '13 at 21:02
  • Its always nice to know something did helped. If you found the answer of use, an up vote is always appreciated ;) – MadProgrammer Apr 15 '13 at 21:44

0 Answers0