问题描述
我想获取pdf格式的gridview数据...代码工作正常,意味着打开pdf时下载完bt,然后无法打开...错误是:-文件可能损坏且无法修复...
所以我该怎么办?plz可以帮助我..my代码是:-
Response.ContentType =应用程序/pdf";
Response.AddHeader("content-disposition","attachment; filename = UserDetails.pdf");
Response.Cache.SetCacheability(HttpCacheability.NoCache);
StringWriter sw = new StringWriter();
HtmlTextWriter hw =新的HtmlTextWriter(sw);
GrdATDataView.AllowPaging = false;
GrdATDataView.DataBind();
GrdATDataView.RenderControl(hw);
GrdATDataView.HeaderRow.Style.Add("width","15%");
GrdATDataView.HeaderRow.Style.Add("font-size","10px");
GrdATDataView.Style.Add("text-decoration","none");
GrdATDataView.Style.Add("font-family","Arial,Helvetica,sans-serif;");
GrdATDataView.Style.Add("font-size","8px");
StringReader sr = new StringReader(sw.ToString());
文档pdfDoc =新文档(PageSize.A2、7f,7f,7f,0f);
HTMLWorker htmlparser =新的HTMLWorker(pdfDoc);
PdfWriter.GetInstance(pdfDoc,Response.OutputStream);
pdfDoc.Open();
htmlparser.Parse(sr);
//pdfDoc.Close();
Response.Write(pdfDoc);
Response.End();
i want to get gridview data i pdf format...code is worke means downloading done bt when open that pdf then it cant open...error is:-File can damaged and cant repaired...
so what can i do???plz help me ..my code is:-
Response.ContentType = "application/pdf";
Response.AddHeader("content-disposition", "attachment;filename=UserDetails.pdf");
Response.Cache.SetCacheability(HttpCacheability.NoCache);
StringWriter sw = new StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(sw);
GrdATDataView.AllowPaging = false;
GrdATDataView.DataBind();
GrdATDataView.RenderControl(hw);
GrdATDataView.HeaderRow.Style.Add("width", "15%");
GrdATDataView.HeaderRow.Style.Add("font-size", "10px");
GrdATDataView.Style.Add("text-decoration", "none");
GrdATDataView.Style.Add("font-family", "Arial, Helvetica, sans-serif;");
GrdATDataView.Style.Add("font-size", "8px");
StringReader sr = new StringReader(sw.ToString());
Document pdfDoc = new Document(PageSize.A2, 7f, 7f, 7f, 0f);
HTMLWorker htmlparser = new HTMLWorker(pdfDoc);
PdfWriter.GetInstance(pdfDoc, Response.OutputStream);
pdfDoc.Open();
htmlparser.Parse(sr);
//pdfDoc.Close();
Response.Write(pdfDoc);
Response.End();
推荐答案
protected void btnPDF_Click(object sender, ImageClickEventArgs e)
{
Response.ContentType = "application/pdf";
Response.AddHeader("content-disposition", "attachment;filename=UserDetails.pdf");
Response.Cache.SetCacheability(HttpCacheability.NoCache);
StringWriter sw = new StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(sw);
gvdetails.AllowPaging = false;
gvdetails.DataBind();
gvdetails.RenderControl(hw);
gvdetails.HeaderRow.Style.Add("width", "15%");
gvdetails.HeaderRow.Style.Add("font-size", "10px");
gvdetails.Style.Add("text-decoration", "none");
gvdetails.Style.Add("font-family", "Arial, Helvetica, sans-serif;");
gvdetails.Style.Add("font-size", "8px");
StringReader sr = new StringReader(sw.ToString());
Document pdfDoc = new Document(PageSize.A2, 7f, 7f, 7f, 0f);
HTMLWorker htmlparser = new HTMLWorker(pdfDoc);
PdfWriter.GetInstance(pdfDoc, Response.OutputStream);
pdfDoc.Open();
htmlparser.Parse(sr);
pdfDoc.Close();
Response.Write(pdfDoc);
Response.End();
}
这篇关于pdf格式文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!