2

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.

Bobrovsky
  • 13,789
  • 19
  • 80
  • 130
asedra_le
  • 3,079
  • 8
  • 38
  • 56
  • 2
    Duplicate of http://stackoverflow.com/questions/280817/how-to-convert-html-web-page-to-image-format-in-asp-net-web-application and many, many others. Please search first. – John Saunders Jul 05 '09 at 16:07
  • that's good component. But i'm doing my exercise, i need a tutorials to solve my problem by coding not by using a component. – asedra_le Jul 06 '09 at 04:46
  • In terms of your question, there's no such thing as an "ASP.NET page". On the client, it's an HTML page. I don't know of any way to programmatically produce PDF files at all without a library of some kind, and the only thing I can think of for an image is screen shots. I think you should revisit your requirements. – John Saunders Jul 06 '09 at 07:11
  • Can i takes screen shot of my page by using javascript?? – asedra_le Jul 06 '09 at 07:51

2 Answers2

0

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.

cdm9002
  • 1,930
  • 1
  • 15
  • 15
0

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!

Haseeb Zahid
  • 614
  • 6
  • 20
Jaison Joe
  • 11
  • 3