我正在使用带有 iTextSharp 的自定义 Urdu Font Jameel Noori Nastaleeq但它根本没有显示文本。当我使用诸如 times.ttf 等内置表单时,它会显示文本。
代码如下:
private void button1_Click(object sender, EventArgs e)
{
Document document = new Document();
try
{
PdfWriter writer = PdfWriter.GetInstance(document, new System.IO.FileStream("C:\\iTextSharpHelloworld.pdf", System.IO.FileMode.Create));
document.Open();
string fontpath = Environment.GetEnvironmentVariable("SystemRoot") + "\\fonts\\Jameel Noori Nastaleeq.ttf";
//string fontpath = Environment.GetEnvironmentVariable("SystemRoot") + "\\fonts\\times.ttf";
BaseFont basefont = BaseFont.CreateFont(fontpath, BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
iTextSharp.text.Font arabicFont = new iTextSharp.text.Font(basefont, 24, iTextSharp.text.Font.NORMAL, iTextSharp.text.BaseColor.BLUE);
var el = new Chunk();
iTextSharp.text.Font f2 = new iTextSharp.text.Font(basefont, el.Font.Size,
el.Font.Style, el.Font.Color);
el.Font = arabicFont;
PdfPTable table = new PdfPTable(1);
table.RunDirection = PdfWriter.RUN_DIRECTION_RTL;
var str = "نام : ";
PdfPCell cell = new PdfPCell(new Phrase(10, str, el.Font));
table.AddCell(cell);
document.Add(table);
document.Close();
MessageBox.Show("Done");
}
catch (DocumentException de)
{
// this.Message = de.Message;
MessageBox.Show(de.Message);
}
catch (System.IO.IOException ioe)
{
// this.Message = ioe.Message;
MessageBox.Show(ioe.Message);
}
// step 5: we close the document
document.Close();
}
}
更新:设置cell.ArabicOptions = ColumnText.DIGITS_EN2AN;
会以我想要的字体呈现字体,但不会呈现任何其他文本。