如何使用itextsharp在PDF格式的古吉拉特语表单元格中显示字符

时间:2016-12-02 09:02:39

标签: c# itext

您好我尝试使用itextsharp

以pdf格式显示Gujarati字体中的文本
  • 当我直接使用doc.add添加(新词组(“这是一个测试નમસ્તેનમસ્તેનમસ્તે”,f))其作品
  • 但是当我使用pdfpcell意味着在表格单元格中添加它 cell = new PdfPCell(new Phrase(12,“Harikeshનમસ્તે”,f)); 它不工作(显示空白)

你发现总代码我发布了..

请帮助解决这个问题

Document document = new Document(PageSize.A4);
document.SetMargins(88f, 88f, 80f, 30f);
using (System.IO.MemoryStream memoryStream = new System.IO.MemoryStream())
{
    PdfWriter writer = PdfWriter.GetInstance(document, memoryStream);
    Phrase phrase = null;
    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.NOT_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,"Harikesh નમસ્તે", f));
    cell.BorderColor = new iTextSharp.text.Color(229, 229, 229);
    cell.FixedHeight = 10f;
    table.AddCell(cell);                       
    document.Add(table);
    document.Add(new Phrase("This is a test નમસ્તે નમસ્તે નમસ્તે", f));
    filename = filename + 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();
}

1 个答案:

答案 0 :(得分:0)

问题是您使用的字体为12:

cell = new PdfPCell(new Phrase(12,"Harikesh નમસ્તે", f));

固定高度为10f:

cell.FixedHeight = 10f;

您可以尝试升高FixedHeight或将其设置为0,并让它使用此字体的默认高度。