how to convert html <div> to pdf

how to convert html <div> to pdf

本文关键字:to div pdf gt lt html how convert      更新时间:2023-09-26
转换为 PDF。
<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>

这张表我需要转换为pdf。

我尝试使用jspdf和下面提到的功能。

$(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
   );
});
});

它生成了以列数据作为行的pdf。请帮助我。

包含以下脚本文件

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