Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
Hi,
I am facing a problem when trying Export to PDF from popup window.when click on the button for export to pdf it gives error "The document has no pages.".Please try to help me out.i am using iTextSharp.
I am Helpless.It is very urgent.Thanks in Advance
 
Code give in below section.
<table>
          <tr>
               <asp:ImageButton ID="ImageButtonPDF" runat="server" AlternateText="View" ToolTip="Click to view PDF report"
                     ImageUrl="~/Graphics/Buttons/printpreview.gif" OnClick="ImageButtonPDF_Click"  />
         </tr>
 

 
    <tr>
                                        <td>
                                            <asp:GridView ID="Gridview1" BorderStyle="None" runat="server" AutoGenerateColumns="true"
                                                OnRowDataBound="gvRedemptionFunding_RowDataBound" ShowFooter="true"  Gridlines="none">
                                                <EmptyDataTemplate>
                                                    <%= sbEmptyGridTemplate %>
                                                </EmptyDataTemplate>
                                                <HeaderStyle CssClass="reportHeaderTitle" HorizontalAlign="right" />
                                                <RowStyle CssClass="reportGridItem" HorizontalAlign="right" />
                                                <FooterStyle CssClass="reportGridItem" HorizontalAlign="right" Height="30px" Font-Bold="true" />
                                            </asp:GridView>
                                        </td>
                                    </tr>
</table>
 


Code Behind

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, 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();
Edit
No need to mention urgent
Posted 6-Mar-12 3:06am
Edited 6-Mar-12 19:35pm
v5
Comments
Mahmud Hasan at 6-Mar-12 8:14am
   
Edited the question for formatting. Are you using any 3rd party pdf conversion library?
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

  Permalink  
Comments
bubai banerjee at 7-Mar-12 0:41am
   
Not solved my Problem.
bubai banerjee at 7-Mar-12 0:46am
   
Thanks for your time and effort
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Try this
 
Gridview1.RenderControl(hw);
 
 
instead of creating form and adding Gridview to it.
 
 HtmlForm frm = new HtmlForm();
        Gridview1.Parent.Controls.Add(frm);
        frm.Attributes["runat"] = "server";
        frm.Controls.Add(Gridview1);
        frm.RenderControl(hw);
 
  Permalink  
Comments
bubai banerjee at 7-Mar-12 0:45am
   
The document has no pages.Still i am getting error when try to export pdf from
popUp window.As i don't know what the problem is or using "iTextSharp" PDF giving error
bubai banerjee at 7-Mar-12 0:46am
   
Thanks for your time and effort

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

  Print Answers RSS
0 OriginalGriff 505
1 Maciej Los 325
2 Richard MacCutchan 265
3 Mathew Soji 220
4 BillWoodruff 210
0 OriginalGriff 8,804
1 Sergey Alexandrovich Kryukov 7,457
2 DamithSL 5,689
3 Maciej Los 5,279
4 Manas Bhardwaj 4,986


Advertise | Privacy | Mobile
Web03 | 2.8.1411028.1 | Last Updated 7 Mar 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100