ASP.NET page to image or PDF

后端 未结 2 1557
春和景丽
春和景丽 2021-01-22 13:44

I have an ASP.NET page like this:

http://farm4.static.flickr.com/3631/3690714302_c17b259863.jpg

My table is Gridview and some Label, an

2条回答
  •  醉梦人生
    2021-01-22 14:30

    Hai use iTextSharp to convert your webpage to pdf. It looks very nice. Just download the dll file and add reference to your application. Then in button click give the coding as follows.

    Response.ClearHeaders()
        Response.ContentType = "application/pdf"
        Response.AddHeader("content-disposition", attachment; filename="jaison.pdf")
        Response.Cache.SetCacheability(HttpCacheability.NoCache)
        Dim sw As New StringWriter()
        Dim hw As New HtmlTextWriter(sw)
        Me.Page.RenderControl(hw)
        Dim sr As New StringReader(sw.ToString())
        Dim pdfDoc As New Document(iTextSharp.text.PageSize.A2, 10, 10, 10, 10)
    
        Dim htmlparser As New HTMLWorker(pdfDoc)
        PdfWriter.GetInstance(pdfDoc, Response.OutputStream)
        pdfDoc.Open()
        htmlparser.Parse(sr)
        pdfDoc.Close()
        Response.Write(pdfDoc)
        Response.End()
    

    Surely this code will help you.

    All the best!

提交回复
热议问题