iTextSharp 和断字

iTextSharp and Hyphenation

在早期版本的 iTextSharp 中,我通过以下方式合并了断字(例如德语断字):

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

在 iText 的最新版本中,这不再可能作为函数

BaseFont.AddToResourceSearch()

已从 iText 中删除。现在如何替换这个语句?

检查第二版时。在 iText IN ACTION 手册中,声明根本不需要替换,显然。但是,这样做时,不会发生断字(也不会发生错误)。我也使用了更新版本的

itext-hyph-xml.dll

并重新引用它。同样的结果,没有连字符。此文件位于与 iTextSharp.dll 相同的路径上,我已将该路径包含在 CLASSPATH 环境变量中。没有任何帮助。我卡住了,请帮忙。

呼叫 iTextSharp.text.io.StreamUtil.AddToResourceSearch() 适合我:

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());
}

使用 iTextSharp 5.5.11 和 itext-hyph-xml 2.0.0.0 进行测试。输出 PDF: