I found the problem when I tried this answer in VB.NET (little modified) :
Function HtmlToPDF(ByVal Url As String) As MemoryStream
Dim wc As New WebClient
Dim htmlText = wc.DownloadString(Url)
Dim msOutput As New MemoryStream
Dim reader As New StringReader(htmlText)
Dim document As New Document(PageSize.A4, 30, 30, 30, 30)
PdfWriter.GetInstance(document, msOutput)
Dim worker As New HTMLWorker(document)
document.Open()
worker.StartDocument()
worker.Parse(reader)
worker.EndDocument()
worker.Close()
document.Close()
Return msOutput
End Function
I got an error the path is not a legal form in this code :
worker.Parse(reader)
I check the value reader
in debug is Nothing/NULL
but there is value in my htmlText
.
Then, I tried another code but the error still same as before. This is the code :
Function HtmlToPDF(ByVal Url As String) As MemoryStream
Dim wc As New WebClient
Dim htmlText = wc.DownloadString(Url)
Dim msOutput As New MemoryStream
Dim document As New Document(PageSize.A4, 30, 30, 30, 30)
PdfWriter.GetInstance(document, msOutput)
document.Open()
Response.Write(htmlText)
Dim htmlArrayList As New List(Of IElement)
htmlArrayList = HTMLWorker.ParseToList(New StringReader(htmlText), Nothing)
For k As Integer = 0 To htmlArrayList.Count()
document.Add(htmlArrayList(k))
Next
document.Close()
Return msOutput
End Function
The error is same in this code : HTMLWorker.ParseToList(New StringReader(htmlText), Nothing)
Where is the problem? VB.NET newbie here, thanks in advance.