0

我正在尝试使用 VB.NET 和 iTextSharp 将网页转换为 PDF。我尝试了很多不同的示例,但似乎没有任何效果(至少对我而言)。这是我得到的最接近的,但Invalid nested tag head found, expected closing tag script无论解析哪个网页,XMLWorkerHelper 总是抛出异常。

Dim webClient As New System.Net.WebClient      
Dim result As String = webClient.DownloadString("http://google.com")        
Dim doc As New Document(PageSize.A4)
Dim writer As PdfWriter = PdfWriter.GetInstance(doc, New System.IO.FileStream("c:\test.pdf", System.IO.FileMode.Create))
Dim sr As New System.IO.StringReader(result)
Try
    XMLWorkerHelper.GetInstance().ParseXHtml(writer, doc, sr)
Catch ex As Exception

End Try

我正在使用 iTextSharp 5.4.2.0 和 .NET Framework 4。

谢谢

4

1 回答 1

1

Use

var HtmlNode = new HtmlAgilityPack.HtmlDocument();
HtmlNode.OptionOutputAsXml = true;
HtmlNode.Save(your directory); // save a new HTML file converted

then convert from the new HTML.

于 2014-03-06T20:00:04.410 回答