简体   繁体   English

使用asp.net将并排放置的2个gridview和图像导出为pdf

[英]Export 2 gridviews which are placed side by side and images to pdf using asp.net

I am working in asp.net, have two gridviews which are placed near each other, There are images which are acting as borders on the side of the Grid. 我在asp.net中工作,有两个彼此靠近放置的gridview,在Grid侧面上有充当边框的图像。 Please can you help if this grids and the side images can be exported to pdf in asp.net? 如果此网格和侧面图像可以在asp.net中导出为pdf,请提供帮助吗?

网页图片

iTextSharp can help you. iTextSharp可以为您提供帮助。

Put your grids and image inside an panel. 将网格和图像放入面板中。

<asp:Panel ID="pnlGrids" runat="server">
      <<YourGrids and Border Image >>
</asp:Panel>
<asp:Button ID="btnExportAsPDF" runat="server" OnClick="btnExportAsPDF_Click">

In code behind 在后面的代码中

using System.Data;
using iTextSharp.text;
using System.IO;
using iTextSharp.text.html.simpleparser;
using iTextSharp.text.pdf;

protected void btnExportAsPDF_Click(object sender, EventArgs e)
{
    Response.ContentType = "application/pdf";
    Response.AddHeader("content-disposition", "attachment;filename=Panel.pdf");
    Response.Cache.SetCacheability(HttpCacheability.NoCache);
    StringWriter sw = new StringWriter();
    HtmlTextWriter hw = new HtmlTextWriter(sw);
    pnlGrids.RenderControl(hw);
    StringReader sr = new StringReader(sw.ToString());
    Document pdfDoc = new Document(PageSize.A4, 10f, 10f, 100f, 0f);
    HTMLWorker htmlparser = new HTMLWorker(pdfDoc);
    PdfWriter.GetInstance(pdfDoc, Response.OutputStream);
    pdfDoc.Open();
    htmlparser.Parse(sr);
    pdfDoc.Close();
    Response.Write(pdfDoc);
    Response.End();     
}

Hope this helps to move you on. 希望这能帮助您前进。 Don't forget to accept as answer if it helps! 如果有帮助,别忘了接受答案!

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

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