我正在使用Itext Sharp并尝试将我的.aspx网页转换为PDF。我在Visual Basic中使用Web窗体和编程。网页本身就是一个包含大量数据的表。我想从页面中取出表格并将其制作成pdf格式。网页需要传递变量buildingID才能正确显示表中的数据,所以我尝试使用Web Client捕获当前网页,但它给了我500个内部服务器错误。如何捕获当前网页以便将其传递给String Reader?
这是我到目前为止的代码:
Dim ms As New MemoryStream()
Dim document As New Document(PageSize.A4, 25, 25, 30, 30)
Dim writer As PdfWriter = PdfWriter.GetInstance(document, ms)
document.Open()
Dim wc As New WebClient()
Dim url As String = HttpContext.Current.Request.Url.AbsoluteUri
Dim htmlText = wc.DownloadString(url) <----Error is here
Response.Write(htmlText)
Dim strreader As New StringReader(htmlText)
Dim htmlarraylist As List(Of IElement) = HTMLWorker.ParseToList(strreader, Nothing)
For i = 0 To htmlarraylist.Count
document.Add(htmlarraylist(i))
Next
document.Close()