Click here to Skip to main content
15,888,330 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
I am trying to implement a web page..The page is showing a gridview and a button called generate pdf.I want to know how can i do the following
whenever i'll click into the button it will generate a pdf format of that table...Plz help

I've find a solution regarding this in
http://aspdotnetcodebook.blogspot.com/2009/04/how-to-convert-web-page-to-pdf.html
But can't implement it inside button1_click
Posted
Updated 31-Oct-11 20:30pm
v2
Comments
Anuja Pawar Indore 1-Nov-11 2:31am    
Added link tag

You can use Open Source iSharpText, a .NET port of iText. See:
http://en.wikipedia.org/wiki/IText[^],
http://itextpdf.com/[^],
http://sourceforge.net/projects/itextsharp/[^] (you can download iTextSharp here).

—SA
 
Share this answer
 
Comments
Espen Harlinn 1-Nov-11 9:00am    
All he needs to do is parse the html and generate output using iTextShap - 5'ed!
Sergey Alexandrovich Kryukov 1-Nov-11 11:33am    
Yes, but also using some mapping rules, which should be considered as input meta-data, and the page itself as just data, meta⁰-data.
Thank you, Espen.
--SA
 
Share this answer
 
 
Share this answer
 
 
Share this answer
 
This might be helpfull

[^]
 
Share this answer
 
this is my code, hope it helps

C#
string Pdf = "FullResult(" + DateTime.Now.ToString("ddMMMyyyyhhmmttss") + ").pdf";//Added date to make it unique file name
string PdfPath = Server.MapPath(Pdf);
Document doc = new Document(PageSize.A4, 20, 20, 20, 20);
PdfWriter.GetInstance(doc, new FileStream(PdfPath, FileMode.Create));
string TestName = "Test Name: " ;
doc.Open();
iTextSharp.text.Chunk c2 = new Chunk(GetPData(), FontFactory.GetFont("Arial", 16));// GetPData() is the method to get the information
 Paragraph p = new Paragraph(c2);
Paragraph Test = new Paragraph(TestName, FontFactory.GetFont("Arial", 16));
doc.Add(Chunk.NEWLINE);
doc.Add(p);
doc.Add(new Paragraph("    "));
doc.Add(new Paragraph(Test));
doc.Add(img);
doc.Add(new Paragraph("    "));
doc.Close();
 
Share this answer
 
Thanx all...
I've got this solution

C#
GridView tempGrd = new GridView();
       tempGrd.DataSource = GridView1.DataSource;
       tempGrd.DataBind();

       Response.ContentType = "application/pdf";
       Response.AddHeader("content-disposition","attachment;filename=DataTable.pdf");
       //Response.Cache.SetCacheability(HttpCacheability.NoCache);
       StringWriter sw = new StringWriter();
       HtmlTextWriter hw = new HtmlTextWriter(sw);

       tempGrd.RenderControl(hw);  //We can't use GridView1 directly. This is the way to get the data...
       StringReader sr = new StringReader(sw.ToString());
       Document pdfDoc = new Document(PageSize.A4, 10f, 10f, 10f, 0f);
       HTMLWorker htmlparser = new HTMLWorker(pdfDoc);
       PdfWriter.GetInstance(pdfDoc, Response.OutputStream);
       pdfDoc.Open();
       htmlparser.Parse(sr);
       pdfDoc.Close();
       Response.Write(pdfDoc);
       Response.End();
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900