gpt4 book ai didi

c# - iTextSharp 不呈现自定义乌尔都语字体

转载 作者:行者123 更新时间:2023-11-30 18:35:00 24 4
gpt4 key购买 nike

我正在使用自定义乌尔都语字体 Jameel Noori Nastaleeq使用 iTextSharp,但它根本不显示文本。当我使用 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; 确实以我想要的字体呈现字体,但不呈现任何其他文本。

最佳答案

为了用阿拉伯语书写,我使用了以下字体:

这是一个用阿拉伯语创建订单的例子,乌尔都语也一样

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();`

OutPut

关于c# - iTextSharp 不呈现自定义乌尔都语字体,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15609734/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com