ASP.NET | Esportare una gridview in PDF
La seguente procedura permette di esportare una gridview in un file pdf utilizzando la libreria ITextSharp Imports System.IO Imports iTextSharp.text Imports iTextSharp.text.pdf Imports iTextSharp.text.html Imports iTextSharp.text.html.simpleparser Public Overloads Overrides Sub VerifyRenderingInServ
La seguente procedura permette di esportare una gridview in un file pdf utilizzando la libreria ITextSharp
Imports System.IO Imports iTextSharp.text Imports iTextSharp.text.pdf Imports iTextSharp.text.html Imports iTextSharp.text.html.simpleparser
Public Overloads Overrides Sub VerifyRenderingInServerForm(ByVal control As Control) End Sub
Protected Sub ExportPDF(ByVal gw As GridView, FileName As String) Response.ContentType = “application/pdf” Response.AddHeader(“content-disposition”, “attachment;filename=” & FileName) Response.Cache.SetCacheability(HttpCacheability.NoCache) Dim sw As New StreamWriter() Dim hw As New HtmlTextWriter(sw) gw.RenderControl(hw) Dim sr As New IO.StringReader(sw.ToString()) Dim pdfDoc As New Document(PageSize.A4, 10.0F, 10.0F, 10.0F, 0.0F) Dim htmlparser As New HTMLWorker(pdfDoc) PdfWriter.GetInstance(pdfDoc, Response.OutputStream) pdfDoc.Open() htmlparser.Parse(sr) pdfDoc.Close() Response.Write(pdfDoc) Response.End() End Sub