从gridview c#创建pdf的代码 [英] code to create pdf from gridview c#

查看:65
本文介绍了从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[^]


这篇关于从gridview c#创建pdf的代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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