ASP.NET page to image or PDF

后端 未结 2 1558
春和景丽
春和景丽 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:27

    It can be done by code on the backend that renders the html into a memory Graphic object and then serves that resultant bitmap back, or by printing the page (on the server) through a PDF writer and then capturing the result.

    Javascript, no.

    Or google "online convert html pdf" and use one of those services.

    0 讨论(0)
  • 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!

    0 讨论(0)
提交回复
热议问题