@hersion
希望看了这段代码后,不用我解释你就能明白其中的原因。
Dim sBuff As New StringBuilder("<html>")
sBuff.Append("<head></head>")
sBuff.Append("<body>")
sBuff.Append("<font color='red'>背景背景Test worker背景</font>")
sBuff.Append("<table border=1>")
sBuff.Append("<tr><td><font color='red' size='30' face='Gulim'>背景背景Test worker背景</font></td></tr>")
sBuff.Append("</table>")
sBuff.Append("</body>")
sBuff.Append("</html>")
Dim document As New Document
Dim style As StyleSheet = New StyleSheet
style.LoadTagStyle("td", "face", "Gulim")
style.LoadTagStyle("td", "encoding", "Identity-H")
style.LoadTagStyle("td", "leading", "12,0")
style.LoadTagStyle("body", "face", "SIMHEI")
style.LoadTagStyle("body", "encoding", "Identity-H")
style.LoadTagStyle("body", "leading", "12,0")
FontFactory.RegisterDirectory("c:\Windows\Fonts")
'Dim helv As BaseFont = BaseFont.CreateFont("c:\Windows\Fonts\SIMHEI.ttf", BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED)
'Dim iFont As Font = New Font(helv, 12)
Dim selector As New FontSelector
selector.AddFont(FontFactory.GetFont("Gulim", BaseFont.IDENTITY_H, False, 10))
Dim para As Paragraph = New Paragraph(selector.Process("字体选择")) ' New Paragraph("", iFont)
Dim worker As New iTextSharp.text.html.simpleparser.HTMLWorker(document)
Dim stringReader As New StringReader(sBuff.ToString())
Dim pdfWriter As PdfWriter = pdfWriter.GetInstance(document, New FileStream("c:\test0.pdf", FileMode.Create))
document.Open()
Dim p As ArrayList = iTextSharp.text.html.simpleparser.HTMLWorker.ParseToList(stringReader, style)
For k As Integer = 0 To p.Count() - 1
para.Add(DirectCast(p(k), IElement))
Next
document.Add(para)
document.Close()
回复 引用 查看