Click here to Skip to main content
15,891,033 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hii all,

i want to export gridview data in pdf using itextsharp.dll..

my gridview data is export in pdf correctly..but i want to header and page number on all page of PDF.. PLEASE give me suggestion.

my code is. for export in pdf:
C#
using (StringWriter sw = new StringWriter())
           {
               using (HtmlTextWriter hw = new HtmlTextWriter(sw))
               {
                   //To Export all pages
                   GridView2.AllowPaging = false;
                   this.GetChildList();

                   GridView2.RenderControl(hw);
                   StringReader sr = new StringReader(sw.ToString());
                   Document pdfDoc = new Document(PageSize.A4, 10, 10, 10, 50);

                   HTMLWorker htmlparser = new HTMLWorker(pdfDoc);
                   PdfWriter.GetInstance(pdfDoc, Response.OutputStream);
                   pdfDoc.Open();
                   htmlparser.Parse(sr);
                   pdfDoc.Close();

                   Response.ContentType = "application/pdf";
                   Response.AddHeader("content-disposition", "attachment;filename=GridViewExport.pdf");
                   Response.Cache.SetCacheability(HttpCacheability.NoCache);
                   Response.Write(pdfDoc);
                   Response.End();
               }
           }


please help me

thanks in advance..
Posted
Updated 30-May-14 0:05am
v5

If you want to change manually use
http://www.pdfforge.org/download[^]
 
Share this answer
 
Comments
bindash 29-May-14 2:15am    
thanks for reply.. which version i download and how to use..plz tell me
if you want to create PDf please use itextSahrp.
C#
Font font_heading1 = FontFactory.GetFont(FontFactory.TIMES_ROMAN, 10f, Font.BOLD, BaseColor.WHITE);

 PdfPTable table40 = new PdfPTable(8);
           table40.TotalWidth = 480f;
           table40.LockedWidth = true;
           //relative col widths in proportions - 1/3 and 2/3
           float[] widths = new float[] { 1.8f, 2.2f, 2.5f, 1.2f, 1f, 1f, 1.2f, 1f };
           table40.SetWidths(widths);
           table40.HorizontalAlignment = 1;
           PdfPCell cel = new PdfPCell(new Phrase("Sample Id", font_heading1));
           cel.BackgroundColor = new iTextSharp.text.BaseColor(51, 79, 100);
           cel.HorizontalAlignment = 1;
           table40.AddCell(cel);


have a look
www.mikesdotnetting.com/Article/205/Exporting-The-Razor-WebGrid-To-PDF-Using-iTextSharp[^]
http://stackoverflow.com/questions/4553220/how-can-i-add-a-header-to-a-pdf-file-using-itext-in-c?rq=1.[^]
 
Share this answer
 
v5
Comments
bindash 29-May-14 3:20am    
thnks for reply.. i m using itextsharp.. plz read my problem carefully
ErBhati 29-May-14 3:40am    
use PdfPTable and make it according your need. then export it as pdf.

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