【问题标题】:How can I use `https://github.com/ovvn/dom-to-pdf` in a Browser如何在浏览器中使用`https://github.com/ovvn/dom-to-pdf`
【发布时间】:2019-11-19 18:11:10
【问题描述】:

我喜欢在项目中使用https://github.com/ovvn/dom-to-pdf

到目前为止,我使用https://github.com/tsayen/dom-to-imagehttps://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();
        });
};

https://github.com/ovvn/dom-to-pdf 不提供可以集成到我的 HTML 文档中的 JavaScript 文件。这就是为什么我用https://github.com/browserify/browserify自己创建一个JavaScript文件。

  1. 我安装了browserify全局
  2. 我克隆了 repo https://github.com/ovvn/dom-to-pdf
  3. 我跑browserify index.js -o bundle.js

现在我有了 JavaScript 文件,并在我的 HTML 文件中使用它:

<script src="./bundle.js"></script>

它已正确加载。但我不知道如何在我的项目中使用它。

我试过了:

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');
});

在第一种情况下(在 domtopdf 中需要 domtoimage)我收到错误ReferenceError: domtoimage is not defined,在第二种情况下出现ReferenceError: domToPdf is not defined

如何在浏览器中使用https://github.com/ovvn/dom-to-pdf

【问题讨论】:

    标签: javascript node.js pdf


    【解决方案1】:

    您是否使用 npm 来安装这些软件包?我可以看看你的进口和/或要求声明...

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-08-17
    • 2017-12-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-12-09
    • 2017-03-09
    相关资源
    最近更新 更多