2
我使用自定义Urdu字体Jameel Noori Nastaleeq与iTextSharp,但它根本不显示文本。它显示的文字,当我使用内置的报表,如TIMES.TTF等iTextSharp不呈现自定义urdu字体
守则如下:
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;
不渲染字体,我需要的字体,但没有任何其他文本。
首先,我必须道歉,因为我对英语以外的任何语言都不太熟悉。当我尝试使用您提供的字体时,我也看不到任何东西,但是当我尝试其他字体(如Tahoma或Courier)时,我在PDF中看到了文字。当我分析原始PDF文件时,当我使用字体时,字符不会被包含在内。但是,当我改变运行方向时,我会看到你的字体。这让我相信你的特定字体有问题。出于某种原因,iText无法处理RTL。不幸的是,我对字体了解不多,所以我无法帮助太多。 – 2013-03-25 14:13:03
该问题已在itext-questions邮件列表上得到解答:http://itext-general.2136553.n4.nabble.com/Issue-in-rendering-Custom-Urdu-Font-tt4657895.html#a4657907 – mkl 2013-03-26 01:37:48
@ChrisHaas感谢您的回答。 HTML Worker的东西可以帮助整理出来吗? ABCPdf也看不到字体,但是当他们使用HTML代码时,我能够看到它。是否可以在我的HTML或CSS中提及* font-family *并且iTextSharp可以解析它? – Volatil3 2013-03-26 20:23:30