简体   繁体   中英

angularjs create/export html view as pdf

I am using bootstrap to create a modal window, in this window I have some information, some tables and text areas, is it possible to create an .pdf from this .html modal view?

I looked into FileSaver, but this only works well for downloading tables, what I want is almost like a printscreen of the modal window.

covert html to canvas using html2canvas and then use jsPdf to convert to pdf. here is example fiddle

like this

<canvas id="canvas" width="480" height="320"></canvas> 
<button id="download">Download Pdf</button>

html2canvas($("#canvas"), {
    onrendered: function(canvas) {         
        var imgData = canvas.toDataURL(
            'image/png');              
        var doc = new jsPDF('p', 'mm');
        doc.addImage(imgData, 'PNG', 10, 10);
        doc.save('sample-file.pdf');
    }
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM