编程语言
首页 > 编程语言> > c# 使用itext生成pdf,显示中文

c# 使用itext生成pdf,显示中文

作者:互联网

using iTextSharp.text;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using iTextSharp.text.pdf;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
           // File.Create("d:\\a.pdf");
            Document document = new Document();
            BaseFont bf = BaseFont.CreateFont(@"C:\Windows\Fonts\MSYH.TTC,0", BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);
            iTextSharp.text.Font f = new Font(bf,9);
            PdfWriter.GetInstance(document, new FileStream("d:\\a.pdf", FileMode.Create));
            document.Open();
            iTextSharp.text.Paragraph paragraph = new iTextSharp.text.Paragraph("Hello World你好sss",f);
            document.Add(paragraph);
            document.Close(); 
        }
    }
}

 

标签:c#,text,System,itext,iTextSharp,pdf,using,document,BaseFont
来源: https://www.cnblogs.com/chlm/p/12726329.html