React-pdf: How to disable hyphenation?

Created on 19 Sep 2018  路  5Comments  路  Source: diegomura/react-pdf

React-pdf version:
alpha.15

Description:
I would like to disable hyphenation, I tried to do it according to docs by passing identity callback, but I get the following error:
react-pdf.browser.es.js:1067 Uncaught (in promise) TypeError: word.forEach is not a function
at eval (react-pdf.browser.es.js:1067)
at Array.forEach ()
at eval (react-pdf.browser.es.js:1065)
at KPLineBreaker.suggestLineBreak (react-pdf.browser.es.js:1112)
at Typesetter.layoutLineFragments (Typesetter.js:82)
at LayoutEngine$$1.layoutParagraph (LayoutEngine.js:134)
at LayoutEngine$$1.layoutColumn (LayoutEngine.js:92)
at LayoutEngine$$1.layout (LayoutEngine.js:80)
at TextEngine.layout (react-pdf.browser.es.js:3755)
at Text.measureText (react-pdf.browser.es.js:3965)

How to replicate issue including code snippet (if applies):
Font.registerHyphenationCallback(words => words);

question

Most helpful comment

I resolved with this changes in callback:

Font.registerHyphenationCallback(word => (
  [word]
));

All 5 comments

Should be like this:

Font.registerHyphenationCallback(words => (
  words.map(word => [word])
));

Why?

The hyphenation callback takes as argument the array of words you want to render in the doc (in the format of GlyphString), and should return an array of each word splited into pieces where hyphenation can occur. In other words, it should return an array of arrays. If you don't want to break any word, you basically return each word as it was originally and that's it.

Hope this helped.

@diegomura Thx for the explanation and the code snippet, it is working!

This no longer works in version 1.6.3 I'm finding. Can someone verify that's the case for them as well? I get an error saying Font isn't defined

The callback no longer receives all words, but a word at a time. Please check https://react-pdf.org/advanced#hyphenation

I resolved with this changes in callback:

Font.registerHyphenationCallback(word => (
  [word]
));
Was this page helpful?
0 / 5 - 0 ratings