Skip to content

Text with horizontal spaces are going out of cell boundry or text is hidden under the next column. #1065

@urenpatelce

Description

@urenpatelce

Hi There,

I found one issue where we need text wrapping and formatting fully supported in output PDF. While verifying that, I found that when there are many spaces at the start of the string then text is overflowing the cell boundry instead of dropping to the next line.

https://codepen.io/mmghv/pen/YzzNMLO

Use below Javascript code in the console to replicate the issue.


const { jsPDF } = window.jspdf

const jsonBody = [
  ['1', 'Donna', '[email protected]', 'China'],
  ['2', 'Janice', '[email protected]', `TEST`],
  ['3', 'Ruth', '[email protected]', `Trinidad and Tobago
  kasghdkjhashd ljjhaskdjllkadjs
                  ;asdkj;alkldksaf
                              ;ledk;lksdf;lkdf
                                              losdfljhsdlkfjlskdjf`],
  ['4', 'Jason', '[email protected]', `<p>This line has a slight indent: &nbsp;&nbsp;This text starts a bit to the right</p>

<pre>
    Italicized text here. | ''Italicized text here.''
		Strong emphasized | '''Strong emphasized'''
	Strong italic text:-) | '''Strong ''italic text'':-) '''
				Bullet pointed. | * Bullet pointed.
	Numbered list.| 0 Numbered list.
											ISBN 020171499X | isbn 020171499X
											ISBN 020171499X | ISBN 020171499X
	leading space. |  leading space. 
(Where  denotes a tab character.)

</pre>

<ol>
  <li>Gather your ingredients.</li>
  <li>Preheat the oven.</li>
  <li>Mix the batter.</li>
</ol>

<ul>
  <li>Responsive design</li>
  <li>Intuitive interface</li>
  <li>SEO-friendly</li>
</ul>`],
];

function generate() {
  const doc = new jsPDF();

  doc.autoTable({
    // html: '#my-table',
    head: [['ID', 'Name', 'Email', 'Country']],
    body: jsonBody,
    theme: 'grid',
    styles: {},
    columnStyles: { 3: { halign: 'right' }},
  });

  doc.save('table');
}

Verify the final output.

image

If the text is right align then issue becomes worst. I mean for right align automatically the text should be dropped in the next line too.

Please let me know if you need more details.

Thanks for your time.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions