我正在使用jsPDF它工作正常。它将文档下载为" PDF"但问题是我的设计是错误的,我想要在网站上显示的表格。
如何在jsPDF中设置表的列高和宽度?
这是我的剧本
function exportPdf()
{
var pdf = new jsPDF('p', 'pt', 'letter');
// source can be HTML-formatted string, or a reference
// to an actual DOM element from which the text will be scraped.
source = $('#infobox')[0];
// we support special element handlers. Register them with jQuery-style
// ID selector for either ID or node name. ("#iAmID", "div", "span" etc.)
// There is no support for any other type of selectors
// (class, of compound) at this time.
specialElementHandlers = {
// element with id of "bypass" - jQuery style selector
'#infobox': function (element, renderer) {
// true = "handled elsewhere, bypass text extraction"
return true
}
};
margins = {
top: 10,
bottom: 10,
left: 10,
width: "100%"
};
// all coords and widths are in jsPDF instance's declared units
// 'inches' in this case
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) {
// dispose: object with X, Y of the last line add to the PDF
// this allow the insertion of new lines after html
pdf.save('musterData.pdf');
}, margins);
return false;
}
答案 0 :(得分:0)
我已经发布了与您的问题相关的示例代码..该代码将使用jsPDF工具将html表导出为PDF格式
寻找以下几行
doc.cellInitialize();
。 。
doc.cell(leftMargin,topMargin,cellWidth,rowWidth,cellContent,i)
以下是查找我正在讨论的示例代码的链接
How to set column width for generating pdf using jsPDF
如果您这样做,您将获得PDF格式的表格格式。如果您有任何疑问,请告诉我。如果您觉得有帮助,请不要忘记投票