Click here to Skip to main content
15,946,011 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
I am using below code with respective .dll
but it is not working .pdf is coming with blank page
can you help me with it

donot think i havenot populated gridview i populate it through datasource
using iTextSharp.text;
using System.IO;
using iTextSharp.text.pdf;

using iTextSharp.text.html;

using iTextSharp.text.html.simpleparser;
 Response.ContentType = "application/pdf";

        Response.AddHeader("content-disposition", "attachment;filename=Export.pdf");
        Response.Cache.SetCacheability(HttpCacheability.NoCache);
        StringWriter sw = new StringWriter();
        HtmlTextWriter hw = new HtmlTextWriter(sw);
        HtmlForm frm = new HtmlForm();
        GridView1.Parent.Controls.Add(frm);
        frm.Attributes["runat"] = "server";
        frm.Controls.Add(GridView1);
        frm.RenderControl(hw);
        StringReader sr = new StringReader(sw.ToString());
        Document pdfDoc = new Document(PageSize.A4, 100, 100, 100, 100);
        HTMLWorker htmlparser = new HTMLWorker(pdfDoc);
        PdfWriter.GetInstance(pdfDoc, Response.OutputStream);
        pdfDoc.Open();
        htmlparser.Parse(sr);
        pdfDoc.Close();
        Response.Write(pdfDoc);
        Response.End();


    }
    public override void VerifyRenderingInServerForm(Control control)
    {
        

        /* Verifies that the control is rendered */

    }


[Edited]Code is wrapped in "pre" tag[/Edited]
Posted
Updated 30-Apr-11 21:09pm
v3
Comments
Sandeep Mewara 1-May-11 2:24am    
I don't see anywhere in your code where you populate grid with values!
nilu16 1-May-11 2:56am    
i have populate it through sqldatasource properties
Sandeep Mewara 1-May-11 3:08am    
And where is that property? :doh:
nilu16 1-May-11 3:16am    
in gridview task choose data source
Sandeep Mewara 1-May-11 3:21am    
You debugged and see the Page Life cycle? Is there anything in grid when exporting? I doubt.

I can't find anything strange in your code. BTW Did you get any error message? Check in firefox console or something....

BTW Check these links...can you see any difference in your coding with these?

Dynamically generate .pdf in ASP.NET[^]

Export GridView To Word Excel PDF CSV Formats in ASP.Net[^]
 
Share this answer
 
In addition to Raja's links I am also suggesting you to check given links
Export gridview to pdf using iTextsharp[^]
Export gridview data to PDF[^] for superb article which will lead you to export gridview data to PDF.
 
Share this answer
 

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