I am getting error on this line of code in itextsharp 5.0.6

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

I am getting error on this line of code in itextsharp 5.0.6

ryan
Hello everyone, I have this code:

Dim Html As String = vbCr & vbLf & "<p class=""bo"">A paragraph</p>    " & vbCr & vbLf & "<ul> " & vbCr & vbLf & "<li>one</li>   " & vbCr & vbLf & "<li>two</li>   " & vbCr & vbLf & "<li>three</li>   " & vbCr & vbLf & "</ul>"
            Dim Html1 As String = RenderControlToString(Page)

            Dim styles As New StyleSheet()
            styles.LoadStyle("bo", "size", "10")
            styles.LoadTagStyle(HtmlTags.H1, HtmlTags.FONT, "59")
            styles.LoadTagStyle(HtmlTags.H1, HtmlTags.COLOR, "#ff0000")
            styles.LoadTagStyle(HtmlTags.UL, HtmlTags.INDENT, "10")
            styles.LoadTagStyle(HtmlTags.LI, HtmlTags.LEADING, "16")

            Using document As New Document(PageSize.A4, 10.0F, 10.0F, 100.0F, 0.0F)
                document.SetPageSize(iTextSharp.text.PageSize.A4.Rotate())
                Dim htmlparser As New HTMLWorker(document)
                PdfWriter.GetInstance(document, ms)
                document.Open()

                document.Add(New Paragraph("this is atest"))
                document.Add(New Paragraph("this is a test"))
                Dim strB As New StringBuilder(Html1)
                Using sReader As TextReader = New StringReader(Html1.ToString())
                    Dim list As List(Of IElement) = HTMLWorker.ParseToList(sReader, styles)
                    For Each elm As IElement In list
                        document.Add(elm)
                    Next
                End Using
               
           
            End Using

            'To download the pdf file
            Response.Clear()
            Response.ContentType = "application/pdf"
            Response.AddHeader("content-disposition", "attachment;filename=TestPage.pdf")
            Response.Cache.SetCacheability(HttpCacheability.NoCache)
            Response.Buffer = True
            Response.Clear()
            Dim bytes As Byte() = ms.ToArray()
            Response.OutputStream.Write(bytes, 0, bytes.Length)
            Response.OutputStream.Flush()
            Response.BinaryWrite(bytes)
            Response.End()

        End Using
It keeps throwing error in this line:

 Dim list As List(Of IElement) = HTMLWorker.ParseToList(sReader, styles)

saying object reference not set to an instance of an object. However if I change my Html1 to Html in this line:

Using sReader As TextReader = New StringReader(Html1.ToString())

How can I fix this? Thank you very much.

Regards