[英]How to convert a html table to pdf?
我想将此表生成为pdf文件。 但只显示一列。
在一行( <tr>
)中,我使用了两列( <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");
};
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');
}
也检查这里小提琴
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.