pdfme / pdfme

A TypeScript based PDF generator library, made with React.
https://pdfme.com
MIT License
2.16k stars 192 forks source link

Long word is wrapped differently in PDF preview than in PDF generation #449

Closed nickiepucel closed 1 month ago

nickiepucel commented 2 months ago

Describe the bug

When you have a really long, single word in a textbox, the way it is wrapped in the PDF Preview is different than in the PDF when it is generated.

To Reproduce

This is reproducible in the Address Label Maker demo app.

  1. Enter the following long string in the first cell in the spreadsheet:
123-123-123-123-123-123-123-123-123-123-123-123-123-123-123
  1. Observe how the text is wrapped in the Preview

    image


  2. Click Download

  3. Notice how the word wrapping appears differently in the generated PDF

image

Expected behavior

The word should be wrapped in the same way in both the preview PDF and generated PDF

Your Environment

- pdfme package(@pdfme/generator or @pdfme/ui):

"@pdfme/common": "^3.2.3",
"@pdfme/generator": "^3.2.3",
"@pdfme/schemas": "^3.2.3",
"@pdfme/ui": "^3.2.3",

- pdfme version: 3.2.3
- Operating system: MacOS Sonoma 14.2.1
- Node.js version or Browser name & version: Chromium 122

Your Error Log

n/a

Additional context

none

peteward commented 2 months ago

Hi,

You do get occassional differences between browser and rendered PDF, it's impossible to get them perfectly the same.

However, in this case I'm wondering if it's because you are using -, and the browser might be considering this for a word split where the PDF renderer may not...

peteward commented 1 month ago

Comparison of editor mode then PDF using no spaces (top left), spaces (bottom left), hypens (top-right):

Designer: Screenshot 2024-03-20 at 06 21 15

PDF: Screenshot 2024-03-20 at 06 21 31

So it does appear to be specific to hyphens, and it makes sense when looking at the code.

peteward commented 1 month ago

Further tests and it seems that the browser treats hyphen exactly the same as space and so should we.

Designer Screenshot 2024-03-20 at 06 28 09

PDF Screenshot 2024-03-20 at 06 29 03

I'll write a PR for this soon

hand-dot commented 1 month ago

This issue is fixed by #451 Released as pdfme@3.4.3