C#itext pdf creator希腊字体无法显示

时间:2018-05-25 20:17:41

标签: c# pdf character-encoding itext

我正在尝试创建一个包含希腊字符的pdf。但它根本不显示它们。我知道它与字体有关但我找不到正确的方法来打印希腊字符。

这是我的代码:

PdfWriter writer = PdfWriter.GetInstance(document, new FileStream(filename, FileMode.Create));
        iTextSharp.text.Font font5 = iTextSharp.text.FontFactory.GetFont(FontFactory.HELVETICA, 10);

document.Add(new Paragraph("User: " + NameTxt.Value));

如果NameTxt.Value使用希腊字符,则不会显示

1 个答案:

答案 0 :(得分:2)

试试:

string sylfaenpath = Environment.GetEnvironmentVariable("SystemRoot") + "\\fonts\\sylfaen.ttf";
BaseFont sylfaen = BaseFont.CreateFont(sylfaenpath, BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
Font normal = new Font(sylfaen, 10f, Font.NORMAL, BaseColor.BLACK);

document.Add(new Paragraph("User: " + NameTxt.Value, normal));