c# - 我想使用 iTextSharp 在 PDF 中显示 GUJARATI 字体,我该怎么做?
问题描述
我正在尝试使用 itextsharp 生成 Pdf,并且我也希望在该 pdf 中使用 GUJARTATI 字体。我试过但它显示为空白。请建议我如何做到这一点?
谢谢
这里是 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();
}
解决方案
推荐阅读
- python - 为什么这个分段函数未能通过对象类型断言测试?
- c++ - 在 SDI mfc 应用程序中从视图访问模式对话框
- django - django 3.0 内联管理表单外键-> 外键
- amazon-web-services - 从 S3 到 SQS 的加密存储桶通知
- android - “x”隐藏超类型“枚举”的成员,需要“覆盖”修饰符 - Kotlin
- flutter - Flutter_我如何解决测试问题?
- python - 将 python 文件链接到功能正常的 HTML/CSS 网站
- c++ - BST 高度算法如何计算?
- javascript - 在 Nuxt 中使用 ES6 类作为 vuex 存储状态
- python - 使用 plotly 获取 500 内部服务器错误破折号