我在asp.net工作,有两个相互靠近的网格视图,有一些图像作为网格一侧的边框。如果这个网格和侧面图像可以导出到asp.net中的pdf,请帮忙吗?
答案 0 :(得分:0)
iTextSharp可以帮助你。
将您的网格和图像放在面板中。
<asp:Panel ID="pnlGrids" runat="server">
<<YourGrids and Border Image >>
</asp:Panel>
<asp:Button ID="btnExportAsPDF" runat="server" OnClick="btnExportAsPDF_Click">
在代码背后
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();
}
希望这有助于推动你。如果有帮助,别忘了接受答案!