Jspdf: line break inside tables

Created on 6 Jul 2015  路  5Comments  路  Source: MrRio/jsPDF

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

Code Improvement from_html.js

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 \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?

All 5 comments

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

Was this page helpful?
0 / 5 - 0 ratings

Related issues

glaier picture glaier  路  3Comments

tarekis picture tarekis  路  4Comments

mellisa0109 picture mellisa0109  路  3Comments

0721Betty picture 0721Betty  路  4Comments

Pinank picture Pinank  路  3Comments