javascript - 如何在浏览器中使用`https://github.com/ovvn/dom-to-pdf`
问题描述
我喜欢https://github.com/ovvn/dom-to-pdf
在项目中使用。
到目前为止,我使用https://github.com/tsayen/dom-to-image
(https://github.com/tsayen/dom-to-image在https://github.com/ovvn/dom-to-pdf中是必需的)
像这样
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
.
- 我安装了
browserify
全局 - 我克隆了回购
https://github.com/ovvn/dom-to-pdf
- 我跑
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
在浏览器中使用?
解决方案
您是否使用 npm 安装这些软件包?我可以看看你的进口和/或要求声明......
推荐阅读
- amazon-web-services - 如何将证书 (.crt) 文件导入 AWS CloudHSM 平台
- python - 我有目录中的文件列表,需要以公用名作为降序输入的文件
- android - 显示没有视图引用但应用程序上下文的快餐栏
- ios - 使用两个生产 APN 证书
- java - 在 spring-boot 中使用 2 个数据库的问题。无法自动装配。找不到 EntityManagerFactoryBuilder 的 bean
- java - 尽管添加了 android:usesCleartextTraffic 和 android:networkSecurityConfig,但不允许明文 HTTP 流量
- c++ - 从单链表的头中删除节点后指向垃圾值的头指针
- r - 使用 anomalize::time_decompose() 时出错 - “断言长度不是 1”
- javascript - 如何重命名表格中的列标题
- c# - 列表