简体   繁体   English

angularjs以pdf格式创建/导出html视图

[英]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? 我正在使用引导程序创建模式窗口,在该窗口中我有一些信息,一些表格和文本区域,是否可以从此.html模式视图中创建.pdf?

I looked into FileSaver, but this only works well for downloading tables, what I want is almost like a printscreen of the modal window. 我查看了FileSaver,但这仅适用于下载表,我想要的几乎就像是模态窗口的打印屏幕。

covert html to canvas using html2canvas and then use jsPdf to convert to pdf. 隐蔽HTML使用帆布html2canvas然后用jsPdf转换为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');
    }
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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