简体   繁体   English

通过 wkhtmltopdf 将包含 openlayers 映射的 html 页面转换为 pdf

[英]Converting html page containing openlayers map to pdf via wkhtmltopdf

I have Html page contains tables and OpenLayers map Everything works ok on all the browsers even IE.我有 Html 页面包含表格和 OpenLayers 地图一切都在所有浏览器甚至 IE 上正常工作。 I want to convert this page to pdf so I used wkhtmltopdf and as I read wkhtmltopdf using behind the scene WebKit to render the page so I test the output on Qt Web Browser the browser refuses to display the OpenLayers map due to the error ol-debug.js:18601ReferenceError: Can't find variable: requestAnimationFrame我想将此页面转换为 pdf,所以我使用了 wkhtmltopdf,当我使用幕后 WebKit 读取 wkhtmltopdf 来渲染页面时,我测试了Qt Web 浏览器上的输出,由于ol-debug.js:18601ReferenceError: Can't find variable: requestAnimationFrame错误,浏览器拒绝显示 OpenLayers 地图ol-debug.js:18601ReferenceError: Can't find variable: requestAnimationFrame

ol.PluggableMap.prototype.render = function() {
  if (this.animationDelayKey_ === undefined) {
    this.animationDelayKey_ = requestAnimationFrame(
        this.animationDelay_);
  }
};

because this error wkhtmltopdf convert only the Html tables and ignore the map因为这个错误 wkhtmltopdf 只转换 Html 表并忽略地图

Ps: I use those command for converting Ps:我使用这些命令进行转换

wkhtmltopdf.exe --enable-javascript --no-stop-slow-scripts --javascript-delay 2000 --debug-javascript

any idea or suggestion for a workaround for this issue对此问题的解决方法的任何想法或建议

thanks in advance for the help在此先感谢您的帮助

I found out using Chrome headless is the better and fastest option in converting html to pdf我发现使用 Chrome headless 是将 html 转换为 pdf 的更好和最快的选择

C:\\Google\\Chrome\\Applicationchrome.exe --headless --disable-gpu --run-all-compositor-stages-before-draw --virtual-time-budget=2000 --print-to-pdf=C:\\newPdf.pdf https://openlayers.org/en/latest/examples/animation.html C:\\Google\\Chrome\\Applicationchrome.exe --headless --disable-gpu --run-all-compositor-stages-before-draw --virtual-time-budget=2000 --print-to-pdf=C: \\newPdf.pdf https://openlayers.org/en/latest/examples/animation.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM