之前以为不能实现这种效果,当出现了这个需求,就必须要实现一版,然后so easy,以下实现的代码:

html2canvas(document.querySelector("#capture")).then(canvas => {
var imgUri = canvas.toDataURL("image/png").replace("image/png", "image/octet-stream"); // 获取生成的图片的url
window.location.href= imgUri;
// document.body.appendChild(canvas)
});
更多功能参考: https://github.com/linwalker/render-html-to-pdf
网友评论