ASP.NET page to image or PDF

Deadly 提交于 2019-12-02 02:37:05

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.

Jaison Joe

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!

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!