从gridview c#创建pdf的代码
问题描述:
在此代码中我遇到一个问题(错误:文档没有页面),请任何人帮助我解决此问题
in this code im facing a problem that (error:document has no page)plz any one help me hw to solve this problem
using iTextSharp.text.pdf;
using iTextSharp.text.html;
using iTextSharp.text.xml;
using System.Collections.Generic;
using System.IO;
using iTextSharp.text;
using System.ComponentModel;
using System.Web.Services;
using System.Net;
using iTextSharp.text.html.simpleparser;
using iTextSharp.text.pdf.fonts;
using System.Xml.Serialization;
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);
HtmlForm frm=new HtmlForm();
GridView1.AllowPaging = false;
DropDownList1.Parent.Controls.Add(frm);
frm.Attributes["runat"] = "server";
frm.Controls.Add(DropDownList1);
GridView1.Parent.Controls.Add(frm);
frm.Attributes["runat"] = "server";
frm.Controls.Add(GridView1);
frm.RenderControl(hw);
//frm.RenderControl(hw);
//GridView1.DataBind();
//GridView1.RenderControl(hw);
//GridView1.HeaderRow.Style.Add("width", "15%");
//GridView1.HeaderRow.Style.Add("font-size", "10px");
//GridView1.Style.Add("text-decoration", "none");
//GridView1.Style.Add("font-family", "Arial, Helvetica, sans-serif;");
//GridView1.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();
请帮助我解决该问题.
plz help me how to solve this problem
答
有用的代码示例参考,可在以下位置找到: ^ ]
Useful reference with code sample, is available at: http://www.aspsnippets.com/Articles/Export-ASP.Net-GridView-to-PDF-with-Custom-Columns-Widths-using-iTextSharp.aspx[^]