iTextSharp 绘制字体中特殊符号到PDF

时间:2021-04-06 06:37:44

using  iTextSharp.text;
using iTextsharp.text.pdf;
public void DraSymbolToPdf()
{
  Document doc=new Document();
  PdfWriter.GetInstance(doc,new FileStream("test1.pdf",FileMode.Create)); //在运行目录下创建 test1.pdf文件</span>
  doc.Open();
  BaseFont bf=BaseFont.CreateFont("designfont.ttf",BaseFont.IDENTITY_V,BaseFont.EMBEDDED);  //designfont.ttf 自定义字体库的路径</span>
  Font font=new Font(bf,20);
  string codeStr=string.Format("{0}",(char)36); //36 是字符在 ttf字体中的unionCode编码</span>
  ParaGraph pg=new ParaGraph(codeStr,font);
  doc.Add(pg);
  doc.close();
}