简体   繁体   English

如何使用asp.net将gridview图像和数据导出为PDF或使用asp.net将gridview数据导出为PDF

[英]how to export gridview image and data to PDF using asp.net or Export gridview data to PDF using asp.net

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();  
}

You will have to use 3rd party control for that Try using iText Sharp library its free 您将必须使用第三方控件来尝试免费使用iText Sharp库。

for more info go here 欲了解更多信息, 请点击这里

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM