开发者

iTextSharp error: 'HtmlParser' is not declared

开发者 https://www.devze.com 2023-03-22 07:19 出处:网络
I had already import following namespace in my asp.net page Imports iTextSharp Imports iTextSharp.text Imports iTextSharp.text.pdf

I had already import following namespace in my asp.net page

Imports iTextSharp

Imports iTextSharp.text

Imports iTextSharp.text.pdf

Imports iTextSharp.text.html

but still got an error 'HtmlParser' is not declared when compile, what's the problem ?

Thanks

Protected Sub btn_print_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btn_print.Click

    'Get the HTML from GridView1
    Dim sw As New IO.StringWriter()
    Dim htw As New HtmlTextWriter(sw)
    Gridview1.RenderControl(htw)
    Dim html As String = "<html><body>" + sw.ToString() + "</body></html>"
    Dim filename As String = "Temp"
    HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment;FileName=" + filename + ".pdf")

    'Set up the response
    Response.Clear()
    Response.ContentType = "application/pdf"

    'Create 开发者_开发百科pdf document
    Dim document As New iTextSharp.text.Document(PageSize.A4, 80, 50, 30, 65)

    'Create pdf writer, output directly to OutputStream
    Dim writer As iTextSharp.text.pdf.PdfWriter = PdfWriter.GetInstance(document, Response.OutputStream)
    document.Open()

    'Create tempfile to hold the HTML:
    Dim tempFile As String = Path.GetTempFileName()
    Using tempwriter As New IO.StreamWriter(tempFile, False)
        tempwriter.Write(html)
    End Using

    'Parse the HTML into the document
    HtmlParser.Parse(document, tempFile)

    'Cleanup
    document.Close()
    writer.Close()

    'Delete the tempfile:
    File.Delete(tempFile)

    writer = Nothing
    document = Nothing
    Response.[End]()

End Sub
0

精彩评论

暂无评论...
验证码 换一张
取 消