iTextSharp的不会呈现自定义字体乌尔都语 [英] iTextSharp does not render Custom urdu font

查看:483
本文介绍了iTextSharp的不会呈现自定义字体乌尔都语的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用自定义的乌尔都语字体贾米尔努里Nastaleeq 与iTextSharp的,但它没有显示在所有文本。它显示的文字时,我使用内置样TIMES.TTF等形式

I am using custom Urdu Font Jameel Noori Nastaleeq with iTextSharp but it is not showing text at all. It shows text when I use built-in forms like times.ttf etc.

守则如下:

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; 确实在我需要的字体渲染字体,但并没有任何其他文字

Update: Setting cell.ArabicOptions = ColumnText.DIGITS_EN2AN; does render font in my desired font but does not any other text.

推荐答案

在阿拉伯语我用下面的字体写的:

to write in Arabic I use the following font:

下面是创建阿拉伯语订单的例子是乌尔都语<相同/ p>

here is an example to create an Order in Arabic is the same for Urdu

BaseFont basefontArabic = BaseFont.CreateFont("c:\\\\windows\\\\fonts\\\\TIMES.ttf", BaseFont.IDENTITY_H, true);
iTextSharp.text.Font farabicNormal = new iTextSharp.text.Font(basefontArabic, 10, iTextSharp.text.Font.NORMAL);
iTextSharp.text.Font farabicBold = new iTextSharp.text.Font(basefontArabic, 12, iTextSharp.text.Font.BOLD);

 `Document document = new Document(PageSize.A4);
                document.SetMargins(10f, 10f, 10f, 30f);
                PdfWriter writer = PdfWriter.GetInstance(document, new FileStream(FileName+ ".pdf", FileMode.Create));

                document.Open();

                PdfPTable table = new PdfPTable(5) { RunDirection = PdfWriter.RUN_DIRECTION_RTL, HeaderRows = 1 };
                table.SetWidths(new float[] { 1, 1, 1, 2, 1 });

                table.AddCell(new PdfPCell(new Phrase("الكمية", ReportDesigner.farabicNormal)) { GrayFill = 0.95f, HorizontalAlignment=Element.ALIGN_CENTER });
                table.AddCell(new PdfPCell(new Phrase("نوع السلعة", ReportDesigner.farabicNormal)) { GrayFill = 0.95f, HorizontalAlignment = Element.ALIGN_CENTER });
                table.AddCell(new PdfPCell(new Phrase("الوزن الصافي", ReportDesigner.farabicNormal)) { GrayFill = 0.95f, HorizontalAlignment = Element.ALIGN_CENTER });
                table.AddCell(new PdfPCell(new Phrase("س . ف", ReportDesigner.farabicNormal)) { GrayFill = 0.95f, HorizontalAlignment = Element.ALIGN_CENTER });
                table.AddCell(new PdfPCell(new Phrase("الجملة", ReportDesigner.farabicNormal)) { GrayFill = 0.95f, HorizontalAlignment = Element.ALIGN_CENTER });

                foreach (OrderDetailsEntity item in Order.Details)
                {
                    table.AddCell(new PdfPCell(new Phrase(item.Quantité.ToString("N3"), ReportDesigner.farabicNormal)));
                    table.AddCell(new PdfPCell(new Phrase(item.ArticleLigneFacture.Désignation, ReportDesigner.farabicNormal)));
                    table.AddCell(new PdfPCell(new Phrase(item.QantitéEmballage.ToString("N3"), ReportDesigner.farabicNormal)));
                    table.AddCell(new PdfPCell(new Phrase(item.PrixAchatUnitaire.ToString("N3"), ReportDesigner.farabicNormal)));
                    table.AddCell(new PdfPCell(new Phrase(item.TotalLigneFacture.ToString("N3"), ReportDesigner.farabicNormal)));
                }
document.Add(table);
                document.Close();`  



这篇关于iTextSharp的不会呈现自定义字体乌尔都语的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆