Print window does not print whole page in chrome latest version Print window does not print whole page in chrome latest version google-chrome google-chrome

Print window does not print whole page in chrome latest version


You are calling print() directly after you have finished writing the <img> tags. However, it takes time for all those images to load (asynchronously). Thus, by the time you call print(), the images have not yet finished loading and some may not have had their height determined yet, resulting in an unexpected number of pages.

To fix this, you should call print() only after the onload event has fired on all of the image elements. Here is how I solved it:

var nImages = _totalPages;function imageLoaded() {    if (--nImages === 0) {        _printWindow.print();    }}// ...snip...// replace your `for` loop with the following:for (var i = 1; i <= _totalPages; i++) {    var img = new Image;    img.addEventListener('load', imageLoaded);    img.src = /* get the data URL from the canvas */;    // here, add in your style properties    _printWindow.document.body.appendChild(img);}


matomo