hi, is there any way to do a line break inside a table using jsPDF from_html?
I want to do line break in a cell, for example to have this inside a cell;
Name:
MrRio
There is a issue closed that might explain what you want. Check it out #123.
Okay, so in jspdf.debug.js line#4730 there is the relevant line for parsing the table cell.
rowData[headers[j].name] = tableRow.cells[j].textContent.replace(/\r?\n/g, '');
Here it regex-es out the new line character \n with an empty string. So I removed the \n in the regex and added a \n in my HTML instead of a <br>. It's probably workable for my case...so I thought I would share.
And while I'm here, anyone have a usecase for why the n should be part of the regex?
Awesome, works for me @kamikaz1k
only change
rowData[headers[j].name] = tableRow.cells[j].textContent.replace(/r?n/g, '');
to
rowData[headers[j].name] = tableRow.cells[j].textContent.replace(/r/g, '');
in your script jspdf.debug.js line #4730
@kamikaz1k thank you so much. was about to try a different library
We are closing this issue, because we will not support any longer fromHTML and addHTML.
Explaination:
We are working on a new html2pdf plugin, which will be based on html2canvas and our context2d plugin. This should lead to more reliable results for your projects. And it will give us the time to focus on the core functionality of pdf-generation because we will not use our energy for writing/supporting/extending 2 html plugins. If you still want to use addHTML or fromHTML you can still use jsPDF 1.4.1.
Best Regards
Most helpful comment
Okay, so in jspdf.debug.js line#4730 there is the relevant line for parsing the table cell.
rowData[headers[j].name] = tableRow.cells[j].textContent.replace(/\r?\n/g, '');Here it regex-es out the new line character
\nwith an empty string. So I removed the\nin the regex and added a\nin my HTML instead of a<br>. It's probably workable for my case...so I thought I would share.And while I'm here, anyone have a usecase for why the n should be part of the regex?