2

In earlier versions of iTextSharp, I have incorporated hyphenation in the following way (example is for German hyphenation):

HyphenationAuto autoDE = new HyphenationAuto("de", "DR", 3, 3);
BaseFont.AddToResourceSearch(RuntimePath + "itext-hyph-xml.dll");
chunk = new Chunk(text).SetHyphenation(autoDE);

In recent versions of iText, this is no longer possible as the function

BaseFont.AddToResourceSearch()

has been removed from iText. Now how to replace this statement?

When inspecting the 2nd ed. of the iText IN ACTION manual, the statement need not be replaced at all, apparently. When doing so, however, no hyphenation takes place (and no errors occur). I also have taken a newer version of

itext-hyph-xml.dll

and re-referenced it. Same result, no hyphenation. This file resides on the same path as iTextSharp.dll, and I have included the path in the CLASSPATH environment variable. Nothing helps. I'm stuck, please help.

alrts
  • 338
  • 5
  • 12
  • Which versions do you mean by "earlier versions", which do you mean by "recent versions"? – mkl May 11 '17 at 09:01
  • earlier version: itextsharp504.dll, itext-hyph-xml11.dll; recent version: itextsharp559.dll, itext-hyph-xml20.dll – alrts May 11 '17 at 20:15

1 Answers1

2

Calling iTextSharp.text.io.StreamUtil.AddToResourceSearch() works for me:

var content = @"
Allein ist besser als mit Schlechten im Verein: mit Guten im Verein, ist besser als allein.
";
var table = new PdfPTable(1);
// make sure .dll is in correct /bin directory
StreamUtil.AddToResourceSearch("itext-hyph-xml.dll");

using (var stream = new MemoryStream())
{
    using (var document = new Document(PageSize.A8.Rotate()))
    {
        PdfWriter.GetInstance(document, stream);
        document.Open();
        var chunk = new Chunk(content)
            .SetHyphenation(new HyphenationAuto("de", "DR", 3, 3));
        table.AddCell(new Phrase(chunk));
        document.Add(table);
    }
    File.WriteAllBytes(OUT_FILE, stream.ToArray());
}

Tested with iTextSharp 5.5.11 and itext-hyph-xml 2.0.0.0. Output PDF:

enter image description here

kuujinbo
  • 9,272
  • 3
  • 44
  • 57