Originally posted by Gizzmo Zeuzere:
Thanks but it doesn't work. In fact, it prints only the first page and I don't see how to print the others.
What you have to do is calculate the number of pages and check if all the pages have been printed by putting the following if loop in your print method.
if ( pageIndex >= totalNumPages ) {
return Printable.NO_SUCH_PAGE;
}
To calculate the totalNumPages you have to first calculate the page height and the height of the component(e.g panel) you are trying to print.
double pageHeight = pageFormat.getImageableHeight();
double componentHeight = component.getSize().height;
int totalNumPages = (int) Math.ceil(componentHeight/pageHeight);
------------------