ASP.NET page to image or PDF

血红的双手。 提交于 2019-12-02 03:44:38

问题


I have an ASP.NET page like this:

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

My table is Gridview and some Label, anybody can tell me how to create a button to convert my page to image or PDF file and save it to desktop.


回答1:


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.




回答2:


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!



来源:https://stackoverflow.com/questions/1084321/asp-net-page-to-image-or-pdf

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