2008年2月3日 星期日

iTextSharp 加中文支援 (Chinese Support)

1. Include "iTextSharp" Library

Imports iTextSharp.text
Imports iTextSharp.text.pdf


2. Set Chinese Base Font

' KAIU.TTF - 繁體字 & SIMHEI.TTF - 簡體字
FontPath As String = "c:\windows\fonts\KAIU.TTF"
Dim bf As BaseFont = BaseFont.CreateFont(FontPath, BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED)
Dim fn As Font = New Font(bf, 10)


3. Example:

Dim tab As New PdfPTable(3)
Dim headerwidth() As Single = {50, 25, 25}
tab.SetWidths(headerwidth)
tab.HeaderRows = 1
tab.AddCell(New Paragraph("日期", fn))


Reference:
http://unruledboy.cnblogs.com/archive/2005/08/30/DataTable2PDF.html

沒有留言: