html2pdf.js: Can't get table width to fit to page
Hi, I’ve got a page with an HTML table on it, set to 100% width on the page. I’d like to output the table into a PDF which fits the table to the width of the page and the document will create as many pages as is necessary for the whole table. My code is as follows:
html2pdf($('div.node-content')[0], {
filename: 'myReport.pdf',
margin: 0,
image: { type: 'jpeg', quality: 0.98 },
html2canvas: { dpi: 192, letterRendering: true },
jsPDF: { format: 'a4', orientation: 'p' }
});
I’ve found that the table does not fit the PDF page width and a couple of columns on the right of the table are clipped off. I’ve experimented with the format option in the jsPDF setting as well as the margin option but I can’t seem to affect this behaviour.
Any thoughts on how to do this would be much appreciated. John
About this issue
- Original URL
- State: open
- Created 7 years ago
- Comments: 22 (3 by maintainers)
Yes - the fit-to-width option would meet my needs. Thanks.
same here
Right, I hear you. There have been a few requests for “single-page PDFs”, where the entire content would be shrunk down to the page size - this might fall into that category. Or more generally, a “fit-to-width” option (which could still span multiple pages).
Currently html2pdf just restricts the page size and lets the content re-flow naturally to fit in the space. It works well for many circumstances, but it sounds like it’s not perfect for yours. I’ll add this to the project tracking for the single-page PDFs, might be a while until I get to it though!
Hello! This is what worked for me is (but the solution is feasible because I don’t need it portrait, and the format is just for view mode, when you actually print it you select A4): jsPDF: {orientation: ‘landscape’, format: ‘a3’}
Same probleme here 😃
Hello, Affects me as well
Hi everyone, I haven’t forgotten about this, but time is short these days. I hope I’ll be able to get to this soon.