iTextSharp和断字
在iTextSharp的早期版本中,我以以下方式合并了断字(例如德语断字): 在iText的最新版本中,这不再可能作为函数iTextSharp和断字,itext,hyphenation,Itext,Hyphenation,在iTextSharp的早期版本中,我以以下方式合并了断字(例如德语断字): 在iText的最新版本中,这不再可能作为函数 BaseFont.AddToResourceSearch() 已从iText中删除。现在,如何替换此语句 当检查iText IN ACTION手册第二版时,显然根本不需要替换该声明。但是,执行此操作时,不会发生断字(也不会发生错误)。我还拍了一个新版本的 itext-hyf-xml.dll 并重新引用了它。相同的结果,没有断字。该文件与iTextSharp.dll位于同一
BaseFont.AddToResourceSearch()
已从iText中删除。现在,如何替换此语句
当检查iText IN ACTION手册第二版时,显然根本不需要替换该声明。但是,执行此操作时,不会发生断字(也不会发生错误)。我还拍了一个新版本的
itext-hyf-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:
您所说的“早期版本”是指哪些版本?您所说的“最新版本”是指哪些版本?早期版本:itextsharp504.dll,itext-hyf-xml11.dll;最新版本:itextsharp559.dll,itext-hyf-xml20.dll这对我来说非常有效。非常感谢kuujinbo。
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());
}