【问题标题】:iTextSharp and HyphenationiTextSharp 和连字符
【发布时间】:2017-05-11 06:41:27
【问题描述】:

在 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 环境变量中。没有什么帮助。我卡住了,请帮忙。

【问题讨论】:

  • “早期版本”是指哪些版本,“最近版本”是指哪些版本?
  • 早期版本:itextsharp504.dll、itext-hyph-xml11.dll;最新版本:itextsharp559.dll、itext-hyph-xml20.dll

标签: itext hyphenation


【解决方案1】:

拨打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:

【讨论】:

  • 这对我来说非常有效。非常感谢 kuujinbo。
猜你喜欢
  • 2012-08-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-09-15
  • 2023-03-27
  • 2013-12-29
  • 2010-11-22
  • 1970-01-01
相关资源
最近更新 更多