[英]How can I use `https://github.com/ovvn/dom-to-pdf` in a Browser
I like to use https://github.com/ovvn/dom-to-pdf
in a project.我喜欢在项目中使用
https://github.com/ovvn/dom-to-pdf
。
Up to now I use https://github.com/tsayen/dom-to-image
( https://github.com/tsayen/dom-to-image is requierd in https://github.com/ovvn/dom-to-pdf )到目前为止,我使用
https://github.com/tsayen/dom-to-image
( https://github.com/tsayen/dom-to-image在Z5E056C500A1C4B6A7110B中是必需的。 -to-pdf )
like this像这样
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();
});
};
https://github.com/ovvn/dom-to-pdf does not offer a JavaScript File that I can integrate in my HTML-Document. https://github.com/ovvn/dom-to-pdf不提供可以集成到我的 HTML 文档中的 JavaScript 文件。 That is why I create a JavaScript File myself with
https://github.com/browserify/browserify
.这就是为什么我自己使用
https://github.com/browserify/browserify
创建一个 JavaScript 文件的原因。
browserify
globalbrowserify
globalhttps://github.com/ovvn/dom-to-pdf
https://github.com/ovvn/dom-to-pdf
browserify index.js -o bundle.js
browserify index.js -o bundle.js
Now I have the JavaScript File and I use it in my HTML-File:现在我有了 JavaScript 文件,并在我的 HTML 文件中使用它:
<script src="./bundle.js"></script>
It is correcly loaded.它已正确加载。 But I do not know how I to use it in my project.
但我不知道如何在我的项目中使用它。
I tried:我试过了:
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();
});
}
and和
var element = document.getElementById('test');
var options = {
filename: 'test.pdf'
};
domToPdf(element, options, function () {
console.log('done');
});
In the first case (domtoimage is required in domtopdf) I get the error ReferenceError: domtoimage is not defined
and in the second case ReferenceError: domToPdf is not defined
在第一种情况下(domtopdf 中需要 domtoimage)我收到错误
ReferenceError: domtoimage is not defined
而在第二种情况下ReferenceError: domToPdf is not defined
How can I use https://github.com/ovvn/dom-to-pdf
in a Browser?如何在浏览器中使用
https://github.com/ovvn/dom-to-pdf
?
Did you use npm to install these packages?您是否使用 npm 安装这些软件包? Could I see your imports and/or require statements...
我可以看看你的进口和/或要求声明......
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.