Search code examples
javaitextitext7hyphenation

How to configure hyphenation by iText7?


I try to hyphenate a String with the iText7 hyphenation.
I used the example Code, but it returns null and not a hyphenated String or Hyphenation Object:

Hyphenator h = new Hyphenator("de", "DE", 2, 2);
Hyphenation s = h.hyphenate("Leistungsscheinziffer");
System.out.println(s);//this is null and not "Lei-stungs-schein-zif-fer"

My depenedncies from the pom.xml are:

<dependency>
    <groupId>com.itextpdf</groupId>
    <artifactId>layout</artifactId>
    <version>7.1.2</version>
</dependency>
<dependency>
    <groupId>com.itextpdf</groupId>
    <artifactId>hyph</artifactId>
    <version>7.1.2</version>
    <scope>test</scope>
</dependency>

Is there any I forgot to configure?

Thank you for helping me to solve this. :)


Solution

  • You have hyph as a test dependency (see <scope>). Which means, it is only added when you are running tests. If you want to use hyph in non-test environment, make sure the dependency is e.g. compile (default is compile):

    <dependency>
        <groupId>com.itextpdf</groupId>
        <artifactId>hyph</artifactId>
        <version>7.1.2</version>
    </dependency>