how to convert html <div> to pdf

前提是你 提交于 2019-12-13 11:15:16

问题


<div id="content">
 <h3>Hello</h3>
     <table id = "tblHeader" >
        <tbody>
           <tr>
             <td width="10%">name</td>                      
             <td width="15%">id</td>
             <td width="27%">Patient Name </td>
             <td width="8%">Age</td>
          </tr>
       </tbody>                
    </table>
</div>
<button id="cmd">generate PDF</button>

This table I need to convert to pdf.

I tried with jspdf and the function noted below.

$(function () {
$('#cmd').click(function () {
    var pdf = new jsPDF('p', 'pt', 'letter'),
    source = $('#tblHeader')[0],
    margins = {
        top: 40,
        bottom: 40,
        left: 40,
        right: 40,
        width: 522
    };

    pdf.fromHTML(
        source,
        margins.left,
        margins.top,
        {
        'width': margins.width 
        },
        function (dispose) {
            pdf.save('Test.pdf');
        },
        margins
   );
});
});

And it generated pdf with column data as rows.Please help me.


回答1:


Include the following script file

    <script src="/Scripts/plugin/jsPdf/jspdf.debug.js"></script>


来源:https://stackoverflow.com/questions/29532140/how-to-convert-html-div-to-pdf

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!