I am working on printing my HTML table data into PDF without using any javascript library. I am generating this on the basis of dropdown option selected. This data is dynamic depending on what options are selected. For some option value data is small and for some option value table data get expanded. So I want to print those data in PDF. Is there any possible way to do this?
This is the function to export data into PDF format. But this will working fine for less number of columns. When table generated for large number of columns, the data in PDF is not visible fully. So I want to make this function compatible for both less or more number of columns comes.
function exportToPdf(){
var sTable = document.getElementById('rDataDiv').innerHTML;
var style = "<style>";
style = style + "table {width: 100%;font: 12px Calibri;}";
style = style + "table, th, td {border: solid 1px #DDD; border-collapse: collapse;";
style = style + "padding: 2px 3px;text-align: justify;}";
style = style + "</style>";
var title = "<title>"+name+"</title>";
var printWindow = window.open('', '', 'height=700,width=700');
printWindow.document.write('<html moznomarginboxes mozdisallowselectionprint><head>');
printWindow.document.write(title);
printWindow.document.write(style);
printWindow.document.write('</head><body>');
printWindow.document.write(sTable);
printWindow.document.write('</body></html>');
setTimeout(function () {
printWindow.print();
printWindow.close();
}, 100);
}