问题描述
如何使用带有angular2的html2canvas生成输出文件PDF
How to generate an output file PDF using html2canvas with angular2
我试图导入文件html2canvas typescript并做出这样的声明以使用它
I tried to import the file html2canvas typescript and made a declaration like this to use it
declare let html2canvas: Html2CanvasStatic;
但是我没有定义html2canvas
but I get html2canvas is not defined
html2canvas(document.body, {
onrendered: function(canvas) {
document.body.appendChild(canvas);
}
});
我在github html2canvas打字稿
如何在我的应用程序angular2中使用它
how can use this for my application angular2
推荐答案
我可以使用html2canvas进行以下更改:
I could use html2canvas with the followings changes:
package.json:
package.json:
"dependencies": {
"html2canvas": "0.5.0-beta4",
"@types/html2canvas": "0.5.32",
}
使用npm install
后,可以在我的component.ts文件中使用html2canvas,如下所示:
After using npm install
I could use html2canvas in my component.ts files like this:
import * as html2canvas from "html2canvas"
test() {
html2canvas(document.body, {
onrendered: function(canvas) {
var img = canvas.toDataURL()
window.open(img);
}
});
}
无需安装@types/html2canvas
,我可以通过require使用lib,而不能通过import来使用:
Without installing @types/html2canvas
I could use the lib via require but not via the import:
html2canvas = require('hmtl2canvas');
这篇关于html2canvas使用angular2/typescript使用CSS样式呈现文档PDF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!