From sun’s documentation
“The printing system might request that a page be rendered multiple times before moving to the next page.”
The examples always show something like this:
Printable print(Graphics g, PageFormat pageFormat, int page) {
if (page == 0)
do...
else if(page == blah...)
}
If you follow this pattern your code typically works fine because it is explicit based on the page number. Not following this pattern caused me great pain until I realized it was getting called multiple times with the same page number and started to cache the pages.
Why does the java Printable’s print method get called multiple times with the same page number?
The Java printing system is at the mercy of the underlying OS printing system, and that system may request a single page be rendered multiple times.
One reason is banded printing — if the printer doesn’t have enough memory to render the entire page at once — in that case, the OS will ask Java for the page again so it can print the page in strips (“bands”). This is the specific case mentioned in the Java 2D Programmer’s Guide, in the section “Printing Concepts“.
There may be other reasons; it’s really up to the OS’s printing system.