我想使用iTextSharp在PDF中显示GUJARATI字体,怎么办?

时间:2018-07-12 06:37:23

标签: c# itext

我正在尝试使用itextsharp生成Pdf,并且我也想要该pdf中的GUJARTATI字体。我试过了,但是显示空白。请建议我该怎么做?

谢谢

此处是Pdf的ScreenCut:

pdf Screencut

我在这里尝试的代码:

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

0 个答案:

没有答案