Q: When I am printing to a physical printer with Java, the print method in my Printable gets called several times. When I am printing using Qoppa’s library jPDFWriter to print directly to PDF from Java, the print method only gets called once. Why is this?
A: When printing to a physical printer, the Java API can call the print method several times, sometimes more than twice. This was put in place to accommodate printer buffers that can not handle a whole page at once, hence Java can send the data to the printer one ‘buffer-full’ at a time. This can be very inefficient, but it’s Java.
As we understand it, your print method should draw the full page every time that it is called. This is necessary as Java might be using different parts of the page on different calls. The print method should be coded to use the pageIndex value passed into it to determine which page to draw.
jPDFWriter doesn’t need to do this convoluted buffering, so it only needs to call the print method once for every page. As long as you draw the full page on each call, your code should work properly for both physical printers and jPDFWriter.