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

问题描述 投票:0回答:3

您好,我尝试使用 itextsharp 在 pdf 中显示古吉拉特语字体的文本

  • 当我直接使用 doc.add(new Phrase("This is a test નમસ્તે નમસ્તે નમસ્તે", 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();
}
c# itext
3个回答
0
投票

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

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

固定高度为10f:

cell.FixedHeight = 10f;

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


0
投票

使用以下代码片段将古吉拉特语字体打印到 PDF 中。

string ARIALUNI_TFF = HttpContext.Current.Server.MapPath("~/Font/GopikaTwo.ttf");

BaseFont bf = BaseFont.CreateFont(ARIALUNI_TFF, BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);

iTextSharp.text.Font 字体 = null; 字体 = FontFactory.GetFont(ARIALUNI_TFF, BaseFont.IDENTITY_H, BaseFont.EMBEDDED, 12f, iTextSharp.text.Font.NORMAL, BaseColor.BLACK);

段落 GujPara = new Paragraph(new Chunk(gujText, font));

doc.Add(GujPara);


0
投票

string ARIALUNI_TFF = HttpContext.Current.Server.MapPath("~/Font/GopikaTwo.ttf"); BaseFont bf = BaseFont.CreateFont(ARIALUNI_TFF, BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);

iTextSharp.text.Font 字体 = null; 字体 = FontFactory.GetFont(ARIALUNI_TFF, BaseFont.IDENTITY_H, BaseFont.EMBEDDED, 12f, iTextSharp.text.Font.NORMAL, BaseColor.BLACK);

段落 GujPara = new Paragraph(new Chunk(gujText, font)); doc.Add(GujPara);

© www.soinside.com 2019 - 2024. All rights reserved.