首页 > 解决方案 > 我想使用 iTextSharp 在 PDF 中显示 GUJARATI 字体,我该怎么做?

问题描述

我正在尝试使用 itextsharp 生成 Pdf,并且我也希望在该 pdf 中使用 GUJARTATI 字体。我试过但它显示为空白。请建议我如何做到这一点?

谢谢

这里是 PDF 的截屏:

pdf 屏幕截图

这里我尝试的代码:

Document document = new Document(PageSize.A4);
document.SetMargins(88f, 88f, 80f, 30f);
using (System.IO.MemoryStream memoryStream = new System.IO.MemoryStream())
{
    DateTime now = DateTime.Now;
    PdfWriter writer = PdfWriter.GetInstance(document, memoryStream);
    Phrase phrase = new Phrase();
    PdfPCell cell = null;
    PdfPTable maintable = null;
    PdfPTable table = null;
    PdfPTable secondTable = null;
    PdfPCell TableCell = new PdfPCell();
    PdfPCell secondTableCell = new PdfPCell();
    secondTableCell.Border = iTextSharp.text.Rectangle.NO_BORDER;
    iTextSharp.text.Color color = null;
    document.Open();
    string ARIALUNI_TFF = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Fonts), "ARIALUNI.TTF");
    BaseFont bf = BaseFont.CreateFont(ARIALUNI_TFF, BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
    Font f = new Font(bf, 12, Font.NORMAL);
    table = new PdfPTable(1);
    table.TotalWidth = 500f;
    table.LockedWidth = true;
    table.SetWidths(new float[] { 10f });
    cell = new PdfPCell(new Phrase(12, "Yes Boss નમસ્તે", f));
    cell.BorderColor = new iTextSharp.text.Color(229, 229, 229);                        
    table.AddCell(cell);
    document.Add(table);                        
    string filename = "";
    filename = "New" + now.Hour.ToString("00") + now.Minute.ToString("00") + now.Second.ToString("00") + now.Millisecond.ToString() + now.DayOfYear.ToString("000") + now.Day.ToString("00") + now.Month.ToString("00") + now.Year.ToString("0000") + ".pdf";
    document.Close();
    byte[] bytes = memoryStream.ToArray();
    memoryStream.Close();
    Response.Clear();
    Response.ContentType = "application/pdf";
    Response.AddHeader("Content-Disposition", "attachment; filename=" + filename + "");
    Response.Buffer = true;
    Response.Cache.SetCacheability(HttpCacheability.NoCache);
    Response.BinaryWrite(bytes);
    Response.End();
    Response.Close();
}

标签: c#itext

解决方案


推荐阅读