bpampuch / pdfmake

Client/server side PDF printing in pure JavaScript
http://pdfmake.org
Other
11.7k stars 2.04k forks source link

hyphenating text #1511

Open Christian24 opened 6 years ago

Christian24 commented 6 years ago

Hello,

A client asks me for hyphenating text in the pdf output. Looking at https://github.com/bpampuch/pdfmake/issues/264 it is currently not possible. I am thinking about implementing this if it is possible in a reasonable timeframe and you're happy to accept a pull request. My goal would be to offer a callback hyphenateWord(word) that the user can override with whatever functionality the user pleases. I do not want to add new dependencies or locale features to pdfmake.

I think my new code should be executed somewhere here: https://github.com/bpampuch/pdfmake/blob/c2cdd465e7f5146079e7f4a916e37d2d40567393/src/layoutBuilder.js#L679

Am I on the right path?

liborm85 commented 6 years ago

Issue https://github.com/bpampuch/pdfmake/issues/264 is about hiding text without breaking.

Now is supported by issue https://github.com/bpampuch/pdfmake/issues/204 "hard-wrapping" text words (if is word too long is breaked after max size) here: https://github.com/bpampuch/pdfmake/blob/c2cdd465e7f5146079e7f4a916e37d2d40567393/src/layoutBuilder.js#L678-L696

Text hyphenating according to some algorithm is too complicated to implementation. I do not know how it could be solved now.

Christian24 commented 6 years ago

How about offering a callback function like a suggested, so users can implement it themselves? If the callback function is undefined, the library would just fall back to the default behavior that is there now.

SandraK82 commented 5 years ago

One nice way could be the support of softhyphens (html ­ symbol, utf8 U+00AD). This way the dev can supply pre tagged text to pdfmake and pdfmake does not need to rely on anything. If no soft hyphen is supplied, nothing changes. Currently, the softhyphen is interpreted as whitespace, therefore the line break is done correctly, but at the end of a line, the U+00AD needs to replaced by - or U+2011 (which might result in a moving of the word to the next line).

luizbills commented 1 year ago

any progress on this?