I'm trying to create and download an PDF from an existing div with jsPDF.
I have tried many ways but I can't achieve it.
My last try was with @ViewChild
and ElementRef
but doesn't work to.
detail-devis.component.ts:
import {Component, ElementRef, ViewChild} from "angular2/core"; declare let jsPDF; @Component({ selector: 'my-app', template: `<div #test> Hello world </div> <button type="button" (click)="test()">pdf</button> <button (click)="download()">download</button>` }) export class App { @ViewChild('test') el: ElementRef; constructor() { } public download() { var doc = new jsPDF(); doc.text(20, 20, 'Hello world!'); doc.save('Test.pdf'); } public test() { let pdf = new jsPDF('l', 'pt', 'a4'); let options = { pagesplit: true }; pdf.addHTML(this.el.nativeElement, 0, 0, options, () => { pdf.save("test.pdf"); }); } }
Someone know the simplest way to achieve this with Angular 2?