itext sharp/itext 5显示汉字

问题描述 投票:0回答:0

我正在使用 itextsharp 版本 5.5.13.2

我正在尝试How to display chinese characters in pdf file created with iTextSharp中的解决方案,但它没有工作,它没有显示任何内容。我的文档是空白的。

FontSelector selector = new FontSelector();
selector.AddFont(FontFactory.GetFont(FontFactory.TIMES_ROMAN, 12));
selector.AddFont(FontFactory.GetFont("MSung-Light", "UniCNS-UCS2-H", BaseFont.NOT_EMBEDDED));
Phrase ph = selector.Process("全澳甲流确诊病例已破");
document.Add(new Paragraph(ph)); 

我正在寻找解决方案

我也尝试了下面的解决方案,但它错误 b/se AddToResourceSearch 方法不可用。

https://social.msdn.microsoft.com/Forums/en-US/0aba545a-c8ba-4389-9439-fcad416ee60d/display-chinesejapanese-characters-in-pdf-in-itextsharp-in-c?forum= csharpgeneral

public iTextSharp.text.Font CreateChineseFont()
        {
            BaseFont.AddToResourceSearch("iTextAsian.dll");
            BaseFont.AddToResourceSearch("iTextAsianCmaps.dll"); //"STSong-Light", "UniGB-UCS2-H", 
            BaseFont baseFT=BaseFont.CreateFont("STSong-Light", "UniGB-UCS2-H", BaseFont.EMBEDDED);
            iTextSharp.text.Font font = new iTextSharp.text.Font(baseFT);
            return font;
        }


Document document = new Document(PageSize.A4,50, 50, 50, 50);
PdfWriter writer = PdfWriter.GetInstance(document, new FileStream("Chap11.pdf", FileMode.Create));
document.Open();
iTextSharp.text.Font font = CreateChineseFont();
document.Add(new Paragraph("全澳甲流确诊病例已破", font));
document.Close();
itext pdf-generation itext7 cjk
© www.soinside.com 2019 - 2024. All rights reserved.