Javascript 我如何使用`https://github.com/ovvn/dom-to-pdf`在浏览器中
我喜欢使用Javascript 我如何使用`https://github.com/ovvn/dom-to-pdf`在浏览器中,javascript,node.js,pdf,Javascript,Node.js,Pdf,我喜欢使用https://github.com/ovvn/dom-to-pdf在项目中 到目前为止,我使用https://github.com/tsayen/dom-to-image(中需要) 像这样 window.print = function () { return domtoimage.toPng(document.body) .then(function (dataUrl) { var link = document.createElem
https://github.com/ovvn/dom-to-pdf
在项目中
到目前为止,我使用https://github.com/tsayen/dom-to-image
(中需要)
像这样
window.print = function () {
return domtoimage.toPng(document.body)
.then(function (dataUrl) {
var link = document.createElement('a');
link.download = map.printControl.options.documentTitle || "exportedMap" + '.png';
link.href = dataUrl;
link.click();
});
};
不提供可以集成到HTML文档中的JavaScript文件。这就是为什么我自己用https://github.com/browserify/browserify
browserify
globalhttps://github.com/ovvn/dom-to-pdf
browserify index.js-o bundle.js
<script src="./bundle.js"></script>
及
在第一种情况下(DOMTODF中需要DOMTIMAGE),我得到错误ReferenceError:DOMTIMAGE未定义
,在第二种情况下ReferenceError:DOMTODF未定义
如何使用
https://github.com/ovvn/dom-to-pdf
在浏览器中?您是否使用npm安装这些软件包?我可以看看你们的进口和/或要求声明吗 也可能是您使用toPng而不是domToPngI。我在HTML网站中使用它。我克隆并在这个存储库中创建了bundle.js。之后,我将它复制到我的网站,并使用“是”,我确实使用npm安装了该软件包,之后我安装了browserify并创建了bundle.js,现在我想在浏览器的HTML页面中使用它。以下是bundle.js:
window.print = function () {
return domtoimage.toPng(document.body)
.then(function (dataUrl) {
var link = document.createElement('a');
link.download = map.printControl.options.documentTitle || "exportedMap" + '.png';
link.href = dataUrl;
link.click();
});
}
var element = document.getElementById('test');
var options = {
filename: 'test.pdf'
};
domToPdf(element, options, function () {
console.log('done');
});