[英]pdfmake generate PDF from Long HTML Table
I am using pdfmake http://pdfmake.org/ to generate a PDF from an HTML Table and its a great little plugin, but my only problem is I have a very very long table and it gets cut off in width (see screenshot below) 我正在使用pdfmake http://pdfmake.org/从HTML表格及其强大的小插件生成PDF,但是我唯一的问题是我的表格非常长,并且宽度被截断(请参见下面的屏幕截图) )
How do I handle long tables? 如何处理长桌? This is just one of my tables, some tables I have are longer, some are shorter. 这只是我的一张桌子,有些桌子较长,有些较短。 Here is my code: 这是我的代码:
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');
I have my pageSize set to A0 and it still gets cut off...The Height is perfect, just the width gets cut off, please help! 我将pageSize设置为A0,但仍然被截断了。高度是完美的,只是宽度被截断了,请帮忙! I am able to set the width and the height of the page size, but I have no idea what to set it at. 我可以设置页面大小的宽度和高度,但是我不知道该如何设置。 My table has 45 columns with a width of 100 per a column, except for the first one which is 200 for a total of 4600 我的表格有45列,每列的宽度为100,但第一列为200,总计4600
If margins are not an option or a solution, how about a small font style? 如果不能选择边距,那么小的字体样式呢?
styles: {
// FONT SIZE
// SIZE 8
font_xs: { fontSize: 8 },
// SIZE 10
font_sm: { fontSize: 10 },
// SIZE 12
font_md: { fontSize: 12 },
// SIZE 14
font_lg: { fontSize: 14 },
// SIZE 16
font_xl: { fontSize: 16 }
}
Use like this 这样使用
{
text: 'td 0',
style: ['font_sm']
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.