1. 程式人生 > >iText類庫再pdf中顯示中文字體

iText類庫再pdf中顯示中文字體

eat rgs app 文字 csharp base brush str tex

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(); 
        }
    }
}

  

iText類庫再pdf中顯示中文字體