import java.awt.Graphics;
import java.awt.print.PageFormat;
import java.awt.print.Printable;
import java.awt.print.PrinterException;
import java.awt.print.PrinterJob;
/*
* Created on 14-set-2004
*
*/


/**
* @author Laudani
*
*/
public class ProvaPrint implements Printable {


/* (non-Javadoc)
* @see java.awt.print.Printable#print(java.awt.Graphics, java.awt.print.PageFormat, int)
*/
public int print(Graphics arg0, PageFormat arg1, int arg2)throws PrinterException {
System.out.println(arg2);


if(arg2 == 0) {
arg0.drawString("Prova1",(int)arg1.getImageableX()+10,(int)arg1.getImageableY() + 10);
return PAGE_EXISTS;
} else if(arg2 == 1) {
arg0.drawString("Prova2",(int)arg1.getImageableX()+10,(int)arg1.getImageableY() + 10);
return PAGE_EXISTS;
} else if(arg2 == 2) {
arg0.drawString("Prova3",(int)arg1.getImageableX()+10,(int)arg1.getImageableY() + 10);
return PAGE_EXISTS;
} else {
return NO_SUCH_PAGE;
}
}



public static void main(String[] args) {
PrinterJob pj = PrinterJob.getPrinterJob();
PageFormat pf = pj.defaultPage();
pj.setPrintable(new ProvaPrint(), pf);


try {
if (pj.printDialog())
pj.print();
} catch (PrinterException e) {
e.printStackTrace();
}
}
}

when this class start the print method is called 6 times but it prints 3 pages
why?

Ahhh you code is impossible to read.

Hi,

I don't see where you call print 6 times. Did you paste the wrong code?

Next time, Please put your code in CODE tags.

Member Avatar for Nichan

i remember, i had problem with java printing...
when my canon printer window pop up and i clicked cancel, it didn't cancel...
hihihi...
have anyone of you ever experience this?
but when i said, print 2,3, or 4, it's done...(i think so)...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.