在asp.net中生成pdf

时间:2013-09-12 08:08:20

标签: asp.net

以下是我生成pdf的代码。我正在使用pdf标签。代码没有给出任何错误,但pdf也没有生成。

    Dim flname As String = "FeedbackReport"
    Response.AddHeader("content-disposition", "attachment;filename=" & flname)
    Response.Cache.SetCacheability(HttpCacheability.NoCache)
    Dim sw As New StringWriter()
    Dim hw As New HtmlTextWriter(sw)

    Dim frm As New HtmlForm()

    rp.Parent.Controls.Add(frm)
    'GridView1.Parent.Controls.Add(frm);
    '  frm.Attributes("runat") = "server"
    frm.Controls.Add(rp)
    'frm.Controls.Add(GridView1);
    frm.RenderControl(hw)
    Dim sr As New StringReader(sw.ToString())

    ' Dim pdfDoc As New Document(PageSize._11X17, 35.0F, 35.0F, 30.0F, 30.0F)
    Dim pdfDoc As New Document(PageSize._11X17, 20.0F, 20.0F, 30.0F, 30.0F)
    FontFactory.RegisterDirectories()

    Dim htmlparser As New HTMLWorker(pdfDoc)
    PdfWriter.GetInstance(pdfDoc, Response.OutputStream)
    pdfDoc.Open()
    htmlparser.Parse(sr)
    pdfDoc.Close()
    Response.Write(pdfDoc)
    Response.[End]()

1 个答案:

答案 0 :(得分:0)