Pdfmake: hyphenating text

Created on 3 Oct 2018  路  3Comments  路  Source: bpampuch/pdfmake

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?

feature request

Most helpful comment

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).

All 3 comments

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.

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.

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).

Was this page helpful?
0 / 5 - 0 ratings

Related issues

m-brudi picture m-brudi  路  3Comments

michaelqiji picture michaelqiji  路  3Comments

MathLavallee picture MathLavallee  路  3Comments

ValeSauer picture ValeSauer  路  3Comments

imoum007 picture imoum007  路  3Comments