import {Component, ElementRef, ViewChild} from "angular2/core";
declare let jsPDF;
@Component({
selector: 'my-app',
template: `
Download to PDF
Name
{{hero.name}}`,
styles: [
`
.my-class {
background-color: yellow;
}
`
]
})
export class App {
@ViewChild('test') el: ElementRef;
isClassVisible: true;
heroes = [
{id: 1, name:'Superman'},
{id: 2, name:'Batman'},
{id: 5, name:'BatGirl'},
{id: 3, name:'Robin'},
{id: 4, name:'Flash'},
{id: 1, name:'Superman'},
{id: 2, name:'Batman'},
{id: 5, name:'BatGirl'},
{id: 3, name:'Robin'},
{id: 4, name:'Flash'}
];
constructor() {
}
public download() {
var doc = new jsPDF();
doc.text(20, 20, 'Hello world!');
doc.save('Test1.pdf');
}
public pdfHtml() {
alert(this.el.nativeElement.innerHTML);
let pdf = new jsPDF();
let options = {
pagesplit: true
};
pdf.addHTML(this.el.nativeElement, 0, 0, options,() => {
pdf.save("test1.pdf");
});
}
}
angular2 playgroundSystem.import('app')
.catch(console.error.bind(console));
loading...
我是新来jspdf并试图动态生成HTML表格转换为使用JSPDF不使用jQuery PDF格式。请在下面检查下面的评论:
我使用的是angular2,需要将html转换为pdf。
+0
Plunker链接:https://plnkr.co/edit/hAd0lPjyWs0pJOL3sAOp?p=preview –
+0
请与代码的最重要的部分更新的问题。 –
+0
simon您可以在下面的Plunker链接中查看最新的代码: https://plnkr.co/edit/hAd0lPjyWs0pJOL3sAOp?p=preview –