【发布时间】:2014-04-11 16:42:21
【问题描述】:
我可以使用以下脚本从 html 表生成 PDF 文件: 但是我正在逐行获取所有列数据。
请帮助我以表格格式的方式生成 PDF 文件。(带有列边框、边距或填充、标题)在此脚本中
我使用jsPDF lib脚本生成一个html表格到PDF。
var pdf = new jsPDF('p', 'pt', 'letter')
, source = $('#TableId')[0]
, specialElementHandlers = {
// element with id of "bypass" - jQuery style selector
'#bypassme': function(element, renderer){
return true
}
}
, margins = {
top: 20,
bottom: 20,
left: 30,
width: 922
};
pdf.fromHTML(
source // HTML string or DOM elem ref.
, margins.left // x coord
, margins.top // y coord
, {
'width': margins.width // max width of content on PDF
, 'elementHandlers': specialElementHandlers
},
function (dispose) {
pdf.save('Test.pdf');
},
margins
)
编辑:
我也试过这个 sample 下面的函数,但我得到的只是空的 pdf 文件。
function exportTabletoPdf()
{
var doc = new jsPDF('p','pt', 'a4', true);
var header = [1,2,3,4];
doc.table(10, 10, $('#test').get(0), header, {
left:10,
top:10,
bottom: 10,
width: 170,
autoSize:false,
printHeaders: true
});
doc.save('sample-file.pdf');
}
【问题讨论】:
-
我的另一篇文章可能对您有所帮助:enter link description here
标签: jquery html html-table jspdf export-to-pdf