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[^]