Printing a huge document
I'd suggest that you do:

&lt;a href="print_frame.html" target="blank"&gt;Print all items&lt;/a&gt;

where print_frame.html is a simple page that displays an animated loading gif, and contains js that makes an ajax call to printallthisstuff.php.  The success callback for that ajax call will then replace the body content (which currently displays loading.gif) with the html returned from printallthisstuff.php, and call print, as you are doing now.