Angular2 - Generate pdf from HTML using jspdf

后端 未结 5 1437
梦如初夏
梦如初夏 2020-12-20 13:09

For a project I\'m working on I need to be able to generate a PDF of the page the user is currently on, for which I\'ll use jspdf. Since I have a HTML

5条回答
  •  离开以前
    2020-12-20 13:37

    What I found worked was adding:

    
    

    to the index.html file (it could presumably be elsewhere).

    I then used:

    const elementToPrint = document.getElementById('foo'); //The html element to become a pdf
    const pdf = new jsPDF('p', 'pt', 'a4');
    pdf.addHTML(elementToPrint, () => {
        doc.save('web.pdf');
    });
    

    Which no longer uses html2canvas in the code.
    You can then remove the following import:

    import * as html2canvas from 'html2canvas';
    

提交回复
热议问题