如何在angular2中将HTML转换为pdf?

如何在angular2中将HTML转换为pdf?,angular,pdf,typescript,html-to-pdf,Angular,Pdf,Typescript,Html To Pdf,我需要将动态生成的html表转换为pdf格式,并能够将其打印出来。我需要用angular2和打字稿完成 JSPDF适用于angular 2。您需要从dt~下载定义。 将库导入为: import * as jsPDF from "jspdf"; . . . let doc = new jsPDF(); // Add a title to your PDF doc.setFontSize(30); doc.text(12, 10, "Your Title"); // Create your

我需要将动态生成的html表转换为pdf格式,并能够将其打印出来。我需要用angular2和打字稿完成

JSPDF适用于angular 2。您需要从dt~下载定义。 将库导入为:

import * as jsPDF from "jspdf";
.
.
.

let doc = new jsPDF();

// Add a title to your PDF
doc.setFontSize(30); 
doc.text(12, 10, "Your Title");

// Create your table here (The dynamic table needs to be converted to canvas).
let element = <HTMLScriptElement>document.getElementsByClassName("pvtTable")[0];
html2canvas(element)
.then((canvas: any) => {
    doc.addImage(canvas.toDataURL("image/jpeg"), "JPEG", 0, 50, doc.internal.pageSize.width, element.offsetHeight / 5 );
    doc.save(`Report-${Date.now()}.pdf`);
})
从“jsPDF”导入*为jsPDF;
.
.
.
让doc=newjspdf();
//在PDF中添加标题
文件设置字体大小(30);
文件文本(12,10,“您的标题”);
//在此处创建表(需要将动态表转换为画布)。
let element=document.getElementsByClassName(“pvtTable”)[0];
html2canvas(元素)
.然后((画布:任何)=>{
doc.addImage(canvas.toDataURL(“image/jpeg”),“jpeg”,0,50,doc.internal.pageSize.width,element.offsetHeight/5);
doc.save(`Report-${Date.now()}.pdf`);
})
在system.js中,在地图部分添加以下行:

"jspdf": "<myLibs>/jspdf.js",
“jspdf”:“/jspdf.js”,

jsPDF可能重复。我检查过jsPDF,它与angular1一起工作,而不是与angular2一起工作。你能给我看看plunker里的东西吗?我们可以把HTML转换成pdf。我需要将ID为的HTML表格转换为pdf并打印出来。它在angular 2中可以工作。当然,你需要得到
打字
。你是我的英雄。