我正在使用 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 方法不可用。
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();