iTextSharp错误:未声明'HtmlParser'

时间:2011-07-21 02:18:23

标签: asp.net gridview html-parsing itextsharp

我已经在我的asp.net页面中导入了以下命名空间

导入iTextSharp

导入iTextSharp.text

导入iTextSharp.text.pdf

导入iTextSharp.text.html

但仍然出现错误'HtmlParser'在编译时未声明,有什么问题?

由于

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 个答案:

没有答案
相关问题