javaitexthyphenationfrench

itext5: non-English hyphenation not working


I'm generating a PDF in java using itext5. Hyphenation works fine when I use an 'en' HyphenationAuto object. The xml jar is on the class path. In the debugger, the objects are non-null.

When I switch to use 'qq' as the language (a nonsense code), the hyphenation object in the debugger is null, as expected, because the xml jar for hyphenation has no file named qq.xml.

But when I use French-hyphenation instead of English-hyphenation, it fails to hyphenate at all.

When I switch to use 'fr' as the language, the hyphenation object in the debugger is non-null, as expected, showing that at least it's reading the xml file from the underlying jar. BUT the hyphenation is not occurring in the output PDF.

This would indicate a problem with the input text data, but I can't see any issues. There are no non-breaking spaces in the text data.

Changing my JRE's default locale has no effect.

When I use the 'en' hyphenator with French text, there are hyphens at line breaks, but the wrong rules are being applied (and it shows). That indicates no fundamental issue with the French text.

The core itext code is simply:

private static final HyphenationEvent hyphen = new HyphenationAuto("en", "GB", 2, 2);
//...
Paragraph para = new Paragraph();
para.setAlignment(Element.ALIGN_JUSTIFIED); 
para.setHyphenation(hyphen);
Chunk chunk = new Chunk(paragraphText);
para.add(chunk);
doc.add(para);

Solution

  • The fix for me was to get a fresher version of the jar.

    I upgraded from 5.1.0 to 5.1.1.

    I downloaded the 5.1.1 jar from here.

    Perhaps I had a corrupt version of the 5.1.0 jar.