2017-05-11 34 views
2

在早期版本的iTextSharp的,我已經按以下方式合併斷字(例如是德國的斷字):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環境變量中。沒什麼幫助。我卡住了,請幫忙。

+0

版本你說的「早期版本」,你說的「新版本」是指這說的是哪? – mkl

+0

早期版本:itextsharp504.dll,itext-hyph-xml11.dll;最近的版本:itextsharp559.dll,itext-hyph-xml20.dll – alrts

回答

2

調用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:

enter image description here

+0

這對我來說非常合適。非常感謝kuujinbo。 – alrts