eKoopmans / html2pdf.js

Client-side HTML-to-PDF rendering using pure JS.
MIT License
4.17k stars 1.39k forks source link

problem with html2pdf, jsPDF and angular5 #127

Closed djanesch closed 6 years ago

djanesch commented 6 years ago

@eKoopmans i have troubles getting html2pdf running with jsPDF in angular5. so far i have done following steps:

the code where i want to create pdf looks like:

    const pdf = new jsPDF('p', 'pt', 'letter');
    html2pdf(this.document.body, pdf, function(pdfOut) {
      pdfOut.save('Test.pdf');
    });

maybe you could give me a clue whats wrong. if i run the application i get the following error:

html2pdf_js_1.default is not a function

sameerpallav commented 6 years ago

Have you tried the html2pdf.bundle.js?

  1. Add following in angular-cli.json: "scripts": [ "../path/to//html2pdf.bundle.min.js" ] (can skip this if next two steps works)
  2. declare var html2pdf: any; ` const element = ele.nativeElement; const opt = { margin: 0, filename: filename, image: { type: 'jpeg', quality: 1 }, html2canvas: { scale: 3, letterRendering: true, useCORS: true}, jsPDF: { unit: 'mm', format: 'a4', orientation: 'portrait', pagesplit: true} };

    // New Promise-based usage:
    const worker = html2pdf().from(element).set(opt).save()
        .then(done => {
            this.loader = false;
        });`
djanesch commented 6 years ago

@sameerpallav thanks for your code. seems to work perfectly. 1 step with adding to angular-cli.json was not needed in my case.

vstar001 commented 2 years ago

@eKoopmans hi Can you please tell me the solutions for repeating table header every page and extra blank page show issue