【发布时间】:2018-01-04 21:55:14
【问题描述】:
我正在使用 pdfmake http://pdfmake.org/ 从 HTML 表格生成 PDF,它是一个很棒的小插件,但我唯一的问题是我有一个非常长的表格,它的宽度被切断了(见下面的截图)
如何处理长桌?这只是我的一张桌子,我的一些桌子更长,一些更短。这是我的代码:
var widths = [200];
var bodies = [];
$('#cost-matrix-table tr:nth-child(3) td').not(':first').each(function () {
widths.push(100);
});
var rowCounter = 0;
$('#cost-matrix-table tr').not(':nth-child(4)').each(function () {
var data = [];
var columnCounter = 0;
$(this).find("td").each(function () {
if ((rowCounter == 0 || rowCounter == 1) && columnCounter != 0) {
data.push({ text: $(this).text(), colSpan: 2, alignment: 'center' }, {});
}
else {
if (rowCounter == 2) {
if (columnCounter == 0) {
data.push({ text: $(this).text(), style: 'filledHeader' });
}
else {
data.push({ text: $(this).text(), style: 'filledHeader', alignment: 'center' });
}
}
else {
data.push($(this).text());
}
}
columnCounter++;
});
bodies.push(data);
rowCounter++;
});
var docDefinition = {
pageOrientation: 'landscape',
pageMargins: [40, 100, 40, 50],
pageSize: 'A0',
header: { text: $("#dropdown").val(), alignment: 'center', decoration: 'underline', fontSize: 28, bold: true, margin: [40, 40, 0, 0] },
content: [
{
table: {
widths: widths,
body: bodies,
headerRows: 3,
pageBreak: 'before',
dontBreakRows: true,
fontSize: 28
}
}
],
styles: {
filledHeader: {
color: 'white',
fillColor: 'black',
}
}
};
pdfMake.createPdf(docDefinition).download('CostMatrix-' + $("#dropdown").val().replace(/\s/g, '') + '.pdf');
我的 pageSize 设置为 A0,但它仍然被切断...高度完美,只是宽度被切断,请帮助!我可以设置页面大小的宽度和高度,但我不知道要设置什么。我的表有 45 列,每列宽度为 100,除了第一列是 200,总共 4600
【问题讨论】:
标签: javascript jquery pdf pdfmake