2016-10-07 264 views
0

我想将这个表格生成一个pdf文件。但它只显示一列。如何将html表转换为pdf?

连续(<tr>)我使用了2列(<td> </td> <td> </td>)。

但它不显示第二列。

这是表格。

<table class="table"> 
    <tr> 
     <th colspan="2"> <strong> Student Details</strong><th></th> </th> 

    </tr> 

    <tr> 
     <td style="width: 100px;"> 
      <h:outputText value="Student Name"/></td> 
     <td> <h:outputText value="#{collect.s_name}" /> 
     </td></tr> 

</table> 

这是脚本

<script> 
// <![CDATA[  
function generate() { 


    var doc = new jsPDF('p', 'px'); 

    var res = doc.autoTableHtmlToJson(document.getElementById("example2")); 
    var res1 = doc.autoTableHtmlToJson(document.getElementById("example3")); 

     for (var j = 0; j < 6; j++) { 
     doc.autoTable(res.columns, res.data ,{ 
      tableWidth: '800', 
      headerStyles: {rowHeight: 12, fontSize: 9,valign: 'middle' }, 
      bodyStyles: {rowHeight: 10, fontSize: 8, valign: 'middle'}, 
      startY:20, 
     theme: 'grid',overflow: 'linebreak' 
     }); 

     } 
    doc.save("fee-report_#{collect.dept_name}.pdf"); 
}; 
+0

制定你的标题为圆形,清晰的问题可以有很大的帮助,以获得有用的答案。 – peterh

回答

0
function demoFromHTML() { 
var pdf = new jsPDF('p', 'pt', 'letter'); 

pdf.cellInitialize(); 
pdf.setFontSize(10); 
$.each($('#customers tr'), function (i, row){ 
    $.each($(row).find("td, th"), function(j, cell){ 
     var txt = $(cell).text().trim() || " "; 
     var width = (j==4) ? 40 : 70; //make 4th column smaller 
     pdf.cell(10, 50, width, 30, txt, i); 
    }); 
}); 

pdf.save('sample-file.pdf'); 
} 

还要检查以下Fiddle