I like to use https://github.com/ovvn/dom-to-pdf
in a project.
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 )
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. That is why I create a JavaScript File myself with https://github.com/browserify/browserify
.
browserify
globalhttps://github.com/ovvn/dom-to-pdf
browserify index.js -o bundle.js
Now I have the JavaScript File and I use it in my HTML-File:
<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
How can I use https://github.com/ovvn/dom-to-pdf
in a Browser?
Did you use npm to install these packages? Could I see your imports and/or require statements...
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.