我正在尝试将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, ''');
}
有更简单的方法吗?
答案 0 :(得分:0)
我找到了更好,更简单的解决方案:
<script type="text/javascript" language="javascript" src="//cdn.rawgit.com/bpampuch/pdfmake/0.1.26/build/pdfmake.min.js"> </script>
<script type="text/javascript" language="javascript" src="//cdn.rawgit.com/bpampuch/pdfmake/0.1.26/build/vfs_fonts.js"></script>
grid.jqGrid('navGrid', '#ptoolbar', { pdf: true } );
grid.jqGrid('navButtonAdd', '#ptoolbar', {
id:'ExportToPDF',
caption:'',
title:'Export To Pdf',
onClickButton : function(e)
{
try {
// ExportPDF();
$("#orwellRadnici").jqGrid("exportToPdf",{
title: 'PDF Export',
orientation: 'landscape',
pageSize: 'A3',
description: 'Events',
customSettings: null,
download: 'download',
includeLabels : true,
includeGroupHeader : true,
includeFooter: true,
fileName : "File.pdf"
})
} catch (e) {
alert(e);
}
},
buttonicon: 'ui-icon-print'
});
就是这样!