Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
urenpatelce opened this issue Aug 12, 2024 · 1 comment
Labels

Comments

@urenpatelce
Copy link

urenpatelce commented Aug 12, 2024

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', 'dmoore0@furl.net', 'China'],
  ['2', 'Janice', 'jhenry1@theatlantic.com', `TEST`],
  ['3', 'Ruth', 'rwells2@constantcontact.com', `Trinidad and Tobago
  kasghdkjhashd ljjhaskdjllkadjs
                  ;asdkj;alkldksaf
                              ;ledk;lksdf;lkdf
                                              losdfljhsdlkfjlskdjf`],
  ['4', 'Jason', 'jray3@psu.edu', `<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.

@simonbengtsson
Copy link
Owner

Interesting. Even a simple repro like this causes issues with line breaks. Must be something with the width calculation of spaces or similar.

const { jsPDF } = window.jspdf

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

  doc.autoTable({
    body: [[`		                                                                                                                                                              text here`]],
  });

  doc.save('table');
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants