Multi-line text in a cell loses its newline characters
See original GitHub issueI upgraded my jsPDF and autotable to the latest versions recently, and I am encountering an issue where if I am placing multiple paragraphs of text in a table cell, the newline characters are lost and my paragraphs get merged into a single line. E.g, if I had the following text in a cell:
Line 1
Line 2
Line 3
After printing to PDF it would show as:
Line 1 Line 2 Line 3
Below is an example which reproduces the issue:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>Page Title</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<script src="https://unpkg.com/jspdf@latest/dist/jspdf.min.js"></script> <!-- jsPDF v1.5.3-->
<script type="text/javascript" src="jspdf.plugin.autotable.js"></script> <!-- AutoTable v3 RC 2 -->
<script>
function savePdf() {
var elem = document.getElementById('testTable');
var doc = new jsPDF('p', 'pt', 'letter');
doc.autoTable(
{
html: elem,
theme: 'grid',
startY: '70',
margin: { top: 70, horizontal: 40, bottom: 60 },
columnStyles: {
0: { cellWidth: doc.internal.pageSize.width * 0.075 },
1: { cellWidth: doc.internal.pageSize.width * 0.075 },
2: { cellWidth: doc.internal.pageSize.width * 0.1 },
3: { cellWidth: doc.internal.pageSize.width * 0.1 },
4: { cellWidth: doc.internal.pageSize.width * 0.6 - 2 * 40 },
5: { cellWidth: doc.internal.pageSize.width * 0.05 }
}
}
);
doc.save("Test.pdf")
}
</script>
</head>
<body>
<table id='testTable' border='1'>
<thead>
<tr>
<th style='width:5%'>SER</td>
<th style='width:7.5%'>TIME</td>
<th style='width:12.5%'>TO</td>
<th style='width:12.5%'>FROM</td>
<th style='width:52.5%'>MESSAGE</td>
<th style='width:4%'>INIT</td>
</tr>
</thead>
<tbody>
<tr>
<td>4</td>
<td>4444</td>
<td>1</td>
<td>2</td>
<td>LINE1<br>LINE2<br>LINE3<br></td>
<td>AA</td>
</tr>
</tbody>
</table>
<button id='savePdf' onclick='savePdf()'>EXPORT</button>
</body>
</html>
Issue 365 is encountered in this code as well.
Thank you in advance.
Issue Analytics
- State:
- Created 5 years ago
- Comments:6 (1 by maintainers)
Top Results From Across the Web
html - How to show multiline text in a table cell - Stack Overflow
You want to use the CSS white-space:pre applied to the appropriate <td> . To do this to all table cells, for example: td...
Read more >Retaining Line Breaks In Multi-Line Text Fields From Forms Pro
How can we prevent line breaks from being stripped out of multi-line text fields populated in a Forms Pro survey response?
Read more >Fix data that is cut off in cells - Microsoft Support
Wrap text in a cell · Select the cells. ; Start a new line in the cell · Double-click in the cell. ;...
Read more >Copying a multiline text into a single cell in Excel - Super User
Replace all LINEBRK with the newline/linefeed character generated by Alt+0010 (hold down Alt on your keyboard and then hit 0010 on your number ......
Read more >How to Remove Line Breaks in Excel (3 Easy Ways)
A line break is something that allows you to have multiple lines in the same cell ... you may still see some text...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Try v3 released today and see if it works there!
Thanks @glebov21 but I solved in this way: