Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
371 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 Answer

0 votes
by (71.8m points)

Include the following script file

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...