diegomura / react-pdf

📄 Create PDF files using React
https://react-pdf.org
MIT License
14.66k stars 1.16k forks source link

support overflow & white-space css properties #824

Open webdobe opened 4 years ago

webdobe commented 4 years ago

Is your feature request related to a problem? Please describe. I would like to implement https://www.w3schools.com/cssref/css3_pr_text-overflow.asp on a View / Text component that clips off long text

Describe the solution you'd like Based on the docs it does not look like overflow and white space css properties are supported.

Describe alternatives you've considered Not sure I have any.

eglavin commented 4 years ago

Just wondering if any one has a work around for this?

I have content that has lines that have spaces to position the content (i'm getting the data like this, not my choice). In the UI I'm able to use a monospace font and css (white-space: pre-wrap;) to display the content the way i need to, but when it comes to exporting the data with this library I'm unable to use similar features.

Just wondering if @diegomura would have any advice to what I should do? or if you've found a work around your self @webdobe. If not thanks for the time any way!

LitoMore commented 3 years ago

I found an interesting workaround. Check this out:

<Text>{text.split('')}</Text>
eglavin commented 3 years ago

Wow I've been thinking about this problem again recently, yeah that seems to have help fix my problem for now, Thank you very much @LitoMore!

danomatic commented 3 years ago

I found an interesting workaround. Check this out:

<Text>{text.split('')}</Text>

Nice! Here is a version that keeps non-whitespace strings grouped:

text
  .split(/(\s{2,})/g)
  .reduce((strings, string, index) => strings.concat(index % 2 ? string.split('') : string), []);

// returns [ 'Text', ' ', ' ', ' ', ' ', ' ', 'with the proper spacing' ]
ghost commented 2 years ago

@danomatic This doesn't work well with strings with dashes, for example '44D1F7B6-558F-40DD-9252-45BB11DD34D5-44D1F7B6-558F-40DD-9252-45BB11DD34D5'

Screenshot 2022-08-19 at 10 04 59 AM
LitoMore commented 2 years ago

@chathu-novade You could polish @danomatic's code for your case.

ghost commented 2 years ago

@chathu-novade You could polish @danomatic's code for your case.

Seems I have to use soft hyphen to make it work since word-break support is not available.