【发布时间】:2019-10-14 19:55:20
【问题描述】:
我正在尝试将 jqgrid 导出为 pdf 文档。 我尝试了这段代码,但缺少的是将 html 保存到 pdf 文件。 如何添加?
function ExportPDF() {
mya = $("#orwellRadnici").getDataIDs(); // Get All IDs
var data = $("#" + table).getRowData(mya[0]); // Get First row to get the
// labels
var colNames = new Array();
var ii = 0;
for (var i in data) {
colNames[ii++] = i;
} // capture col names
var html = "<html><head>"
+ "<style script="css/text">"
+ "orwellRadnici.tableList_1 th {border:1px solid black; text-align:center; "
+ "vertical-align: middle; padding:5px;}"
+ "orwellRadnici.tableList_1 td {border:1px solid black; text-align: left; vertical-align: top; padding:5px;}"
+ "</style>"
+ "</head>"
+ "<body style="page:land;">";
for (var k = 0; k < colNames.length; k++) {
html = html + "<th>" + colNames[k] + "</th>";
}
html = html + "</tr>"; // Output header with end of line
for (i = 0; i < mya.length; i++) {
html = html + "<tr>";
data = $("#orwellRadnici").getRowData(mya[i]); // get each row
for (var j = 0; j < colNames.length; j++) {
html = html + "<td>" + data[colNames[j]] + "</td>"; // output each Row as
// tab delimited
}
html = html + "</tr>"; // output each row with end of line
}
html = html + "</table></body></html>"; // end of line at the end
html = html.replace(/'/g, ''');
}
有没有更简单的方法来做到这一点?
【问题讨论】:
-
我也试过了,但我得到了空白的 pdf 文件。为什么? onClickButton : function(e) { try { var doc = new jsPDF(); var specialElementHandlers = { '#orwellRadnici': function (element, renderer) { return true; } } doc.fromHTML( $('#orwellRadnici').html(), 15, 15, { 'width': 170, 'elementHandlers': specialElementHandlers }, doc.save('Kadrovska.pdf') ); } 捕捉 (e) { 警报(e); }},
-
如果你使用 Guriddo jqGrid JS 有一个用于 PDF 导出的内置方法。
标签: mvcjqgrid