使用asp.net从弹出窗口导出为PDF [英] Export to PDF from popup window using asp.net

查看:96
本文介绍了使用asp.net从弹出窗口导出为PDF的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我在尝试从弹出窗口导出为PDF时遇到问题.单击导出为pdf的按钮时,出现错误文档无页面.".请尝试帮助我.我正在使用iTextSharp.
我很无助.这很紧急.在此先感谢

代码在以下部分给出.

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

推荐答案

引用此内容
http: //www.eggheadcafe.com/community/asp-net/17/10425399/export-grid-view-ittem-template-values-into-pdf-in-c.aspx [
Refer this
http://www.eggheadcafe.com/community/asp-net/17/10425399/export-grid-view-ittem-template-values-into-pdf-in-c.aspx[^]


试试这个

Try this

Gridview1.RenderControl(hw);



而不是创建表单并向其中添加Gridview.



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);


这篇关于使用asp.net从弹出窗口导出为PDF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆