Reputation: 433
How to set pdf font size for table content using jspdf?
setFontSize doesn't work in my case.
Upvotes: 3
Views: 7261
Reputation: 11
Are you using jspdf-autotable? If so you have to set bodyStyles
instead of styles
bodyStyles:{
fontSize:9
},
It's explained in the docs.
Upvotes: 0
Reputation: 8151
Setting font size for text in a table using jspdf-autotable looks like this:
var doc = new jsPDF();
doc.autoTable({html: '#table', styles: {fontSize: 20}})
doc.save("table.pdf");
Upvotes: 3
Reputation: 11
Edit this: jspdf.plugin.autotable.min.js
Find this part and edit fontSize: textColor:20,halign:"left",valign:"top",fontSize:10,cellPadding:5
the default size is 10 and I change it to 7:
textColor:20,halign:"left",valign:"top",fontSize:7,cellPadding:5
Upvotes: 1
Reputation: 1222
Before printing, make a copy of the table object. Let's say:
let temporalTable = document.getElementsByClassName("table")[0];
Then apply a style to this object. You can use plain JS functions.
And finally:
html2canvas(temporalTableWithNewStyles)
.then((canvas: any) => {
doc.addImage(canvas.toDataURL("image/jpeg"), "JPEG", 0, 50, doc.internal.pageSize.width, element.offsetHeight / 5 );
doc.save(`Report-${Date.now()}.pdf`);
})
Upvotes: 0