Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
374 views
in Technique[技术] by (71.8m points)

javascript - how to convert html <div> to 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>

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Include the following script file

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...