简体   繁体   English

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

[英]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-imagehttps://github.com/tsayen/dom-to-imageZ5E056C500A1C4B6A7110B中是必需的。 -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 文件的原因。

  1. I installed browserify global我安装了browserify global
  2. I cloned the repo https://github.com/ovvn/dom-to-pdf我克隆了https://github.com/ovvn/dom-to-pdf
  3. I run 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.

相关问题 如何试用最新的JS互操作? https://github.com/dart-lang/js-interop - How can I try out the latest JS interop? https://github.com/dart-lang/js-interop 如何处理“已弃用,请使用https://github.com/pillarjs/path-to-regexp”消息 - how to deal with “DEPRECATED use https://github.com/pillarjs/path-to-regexp” message 如何为Tween.js分配额外的属性(https://github.com/sole/tween.js/) - How to assign extra attributes to Tween.js ( https://github.com/sole/tween.js/ ) 来自https://github.com/RubaXa/Sortable的功能要求 - Function required from https://github.com/RubaXa/Sortable 如何使用github.com/1000hz/bootstrap-validator的自定义验证器 - How to use custom validators of github.com/1000hz/bootstrap-validator 如何为(导出到 .xlsx)SheetJS js-xlsx 设置单元格数据的公式:https://github.com/SheetJS/js-xlsx - how to set formula for cell data for (export to .xlsx) SheetJS js-xlsx: https://github.com/SheetJS/js-xlsx 无法使用库https://github.com/hiddentao/linear-algebra运行简单的示例 - Unable to run simple example using library https://github.com/hiddentao/linear-algebra 在本地运行 https://github.com/akella/webgl-mouseover-effects 代码 - Run https://github.com/akella/webgl-mouseover-effects code locally 在异步队列内的函数内进行异步Twitter调用-https://github.com/DeviaVir/zenbot - Async twitter call inside a function that is inside a async queue - https://github.com/DeviaVir/zenbot 无法在meanstack MEANIO上运行localhost:3000,https://github.com/linnovate/mean - cannot run localhost:3000 on meanstack MEANIO, https://github.com/linnovate/mean
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM