iTextSharp导出PDF遇到问题中文无显示!!!
一开始老是少几个显示不完整,一直找代码问题 最后才注意到中文无显示!!
需要像这样
//指定字体库,并创建字体
BaseFont baseFont = BaseFont.CreateFont(
"C:\\WINDOWS\\FONTS\\STSONG.TTF",
BaseFont.IDENTITY_H,
BaseFont.NOT_EMBEDDED);
iTextSharp.text.Font titleFont = new iTextSharp.text.Font(baseFont, 18);
字体文件是window自带字体。
同时需要引入 System.Text.Encoding.CodePages 在Nuget中
并且注册
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
完整例子如下:
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
Document document = new Document();
//指定字体库,并创建字体
BaseFont baseFont = BaseFont.CreateFont(