Javascript “打印窗口”不会在chrome最新版本中打印整个页面
我正在开发一个使用HTML5画布的打印工具。通过打开一个新窗口,将页面画布作为图像写入新窗口文档,然后最终打印窗口文档。作为测试,我尝试在chrome最新版本(46.0.2490.71版)中打印页面(大于100页),但它不会打印整个页面。在chrome打印预览窗口中,只显示部分页面,就像我们打印110页文档一样,这意味着它只显示24或38页(随机显示页面)。但整个页面都添加到新创建的窗口中进行打印。 我使用下面的代码来打印页面Javascript “打印窗口”不会在chrome最新版本中打印整个页面,javascript,html,google-chrome,printing,Javascript,Html,Google Chrome,Printing,我正在开发一个使用HTML5画布的打印工具。通过打开一个新窗口,将页面画布作为图像写入新窗口文档,然后最终打印窗口文档。作为测试,我尝试在chrome最新版本(46.0.2490.71版)中打印页面(大于100页),但它不会打印整个页面。在chrome打印预览窗口中,只显示部分页面,就像我们打印110页文档一样,这意味着它只显示24或38页(随机显示页面)。但整个页面都添加到新创建的窗口中进行打印。 我使用下面的代码来打印页面 var _printWindow = window.open('')
var _printWindow = window.open('');
_printWindow.document.write('<html><BODY>');
_printWindow.document.write('<center>');
for (var i = 1; i <= _totalPages; i++) {
var canvas = this._printpages(i);
_printWindow.document.write('<img src="' + canvas.toDataURL() + '"style="border:1px solid;height:"' + _pageHeight + '"px;margin:0px"><br />');
}
_printWindow.document.write('</center></body></html>');
_printWindow.document.close();
_printWindow.print();
var\u printWindow=window.open(“”);
_printWindow.document.write(“”);
_printWindow.document.write(“”);
对于(var i=1;i您在完成的编写后直接调用print()
,请尝试将样式宽度:100%;
添加到,
标记,我会认为您在写入所有内容之前就已经命中了print语句。这就是为什么它是随机的。您是否检查了canvas变量的打印结果而没有循环?
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);
}