问题
I am trying to export JSON data to PDF using jsPDF and I am not sure how to use jsPDF to accommodate around 15 columns in one page. I tried some of the code found on internet but it is splitting the columns to three rows,but I need to fit all columns to page.
JSON data
jsonResult.Products[{PRODUCT_ID: 123, PRODUCT_NUMBER: "00022", PRODUCT_NAME: "HONDA", PRODUCT_TYPE: "VEHICLE "},
{PRODUCT_ID: 783, PRODUCT_NUMBER: "08412394", PRODUCT_NAME: "HONDA", PRODUCT_TYPE: "MOTOR "}...
I want to display PRODUCT_ID,PRODUCT_NUMBER,PRODUCT_NAME,PRODUCT_TYPE... as headers and similarly around 15 columns which I need to accommodate in page.
Here is code snippet i tried using JSPDF which is splitting the columns to three rows,but i need to accommodate all columns similar to grid data.
var table1 =
jsonResult.Products,
cellWidth = 35,
rowCount = 0,
cellContents,
leftMargin = 2,
topMargin = 12,
topMarginTable = 55,
headerRowHeight = 13,
rowHeight = 9,
l = {
orientation: 'l',
unit: 'mm',
format: 'a3',
compress: true,
fontSize: 8,
lineHeight: 1,
autoSize: false,
printHeaders: true
};
var doc = new jsPDF(l, '', '', '');
doc.setProperties({
title: 'Test PDF Document',
subject: 'This is the subject',
author: 'author',
keywords: 'generated, javascript, web 2.0, ajax',
creator: 'author'
});
doc.cellInitialize();
$.each(table1, function (i, row) {
rowCount++;
$.each(row, function (j, cellContent) {
doc.margins = 1;
doc.setFont("courier ");
doc.setFontType("bolditalic ");
doc.setFontSize(6.5);
doc.cell(leftMargin, topMargin, cellWidth, rowHeight, cellContent, i);
})
})
doc.save('sample Report.pdf');
Please find output of PDF in 3 rows with columns.
Please let me know using JSPDF how can i accommodate 15 columns in a page.
来源:https://stackoverflow.com/questions/61843197/facing-issue-while-exporting-to-pdf-with-more-columns