我正在尝试使用无头chrome版本71自动打印一些带有Chart.JS画布元素的网页,如下所示:start chrome --enable-logging --headless --disable-gpu --run-all-compositor-stages-before-draw --virtual-time-budget=10000 --print-to-pdf=C:\test.pdf example.html
当我在Chrome浏览器中手动从PDF打印时,结果看起来与网页上的效果完全相同:
但在由无头铬创建的PDF中,元素发生了奇怪的变化:
有没有办法让无头chrome像真正的浏览器一样打印PDF文件?
发布于 2019-06-17 00:35:44
问题是,web浏览器会在画布完成之前加载页面,为了避免这种情况,应该生成一些额外的加载
在HTML代码的末尾
添加:
if ( location.href.toUpperCase().indexOf("HTTP") != 0) {
var delay = 1000; // Delaying up load (in milliseconds).
delay = new Date().getTime() + delay,
xhttp = new XMLHttpRequest();
while (new Date().getTime() < delay ) {
xhttp.open("GET", location.href, true);
xhttp.send();
}
}
https://stackoverflow.com/questions/54323712
复制相似问题