ASP.net将gridview数据转换为pdf [英] ASP.net convert gridview data to pdf

查看:73
本文介绍了ASP.net将gridview数据转换为pdf的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我将gridviewdata转换为pdf时,出现以下错误,
''''文件已损坏,无法打开''''

如何使用asp.net3.5

when i''m converting gridviewdata to pdf i''m getting the below error,
''''the file is damaged and couldnot be open ''''

how to fix this error using asp.net3.5

推荐答案

protected void Button4_Click(object sender, EventArgs e)
{
    Response.ContentType = "application/pdf";
    Response.AddHeader("content-disposition","attachment;filename=GridViewExport.pdf");
    Response.Cache.SetCacheability(HttpCacheability.NoCache);
    StringWriter sw = new StringWriter();
    HtmlTextWriter hw = new HtmlTextWriter(sw);
    GridView1.AllowPaging = false;
    GridView1.DataBind();
    GridView1.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);//this is the error line
    pdfDoc.Close();
    Response.Write(pdfDoc);
    Response.End();  
}


问候

:)

我认为这对您有帮助....


Regard
Sham
:)

i think this is helpfull to u....


请参阅以下链接:
文章:
在ASP.NET中全部导出数据 [ ^ ]
如何将GridView数据转换为Excel,PDF,使用C# [ ^ ]
使用c# [如何将GridView数据导出到Asp.net和C#中的pdf文件? [
Refer the links below:
Articles:
All in One Export Data in ASP.NET[^]
How to convert GridView data to Excel, PDF, Word file using C#[^]
Export gridview to pdf in asp.net using c#[^]
Discussions:
How to export GridView data to pdf file in Asp.net and C#?[^]


--Amit


请参阅
想将网格视图转换为pdf [
refer
want to grid view to pdf[^]


这篇关于ASP.net将gridview数据转换为pdf的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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