首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > .NET Framework >

复制网上代码,gridview导出PDF后打开异常

2012-03-17 
复制网上代码,gridview导出PDF后打开错误?C# codeResponse.ContentType application/pdfResponse.Add

复制网上代码,gridview导出PDF后打开错误?

C# code
        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, 10f);        HTMLWorker htmlparser = new HTMLWorker(pdfDoc);        PdfWriter.GetInstance(pdfDoc, Response.OutputStream);        // pdfDoc.Open();        htmlparser.Parse(sr);        // pdfDoc.Close();        Response.Write(pdfDoc);        Response.End(); 

如果我不把pdfDoc.Open()和pdfDoc.Close();注释掉,程序就会提示没有pages;可是当我注释掉后可以导出PDF,导出完后的PDF却打不开,请问是什么原因?

[解决办法]
http://topic.csdn.net/u/20110413/13/75d910f5-6be7-44f2-9bcd-3e7452d52f18.html

热点排行