Hi Ryan
i want to export my gridview to pdf document, i used iTextSharp library, everything is fine but the problem is that
pdf document did not take the GridView Syle like headerStyle, RowStyle, color, font...etc
and here is my code
Public Shared Sub FromGridView(ByVal Grid As GridView, ByVal ReportName As String)
Dim sw As New StringWriter()Dim htw As New HtmlTextWriter(sw)
Dim page As New PageDim form As New HtmlForm
Dim GridStyle As String
page.Controls.Add(form)
form.Controls.Add(Grid)
form.RenderControl(htw)
GridStyle = sw.ToString()
'Set up the response
HttpContext.Current.Response.Clear()
HttpContext.Current.Response.AddHeader("content-disposition", "attachment;filename=" & ReportName & Date.Now.ToShortTimeString & ".pdf")
HttpContext.Current.Response.Charset =
""
HttpContext.Current.Response.ContentType =
"application/pdf"
'Create pdf document Dim PdfDocument As New iTextSharp.text.Document(PageSize.A4)
'Create pdf writer, output directly to OutputStream Dim writer As pdf.PdfWriter = pdf.PdfWriter.GetInstance(PdfDocument, HttpContext.Current.Response.OutputStream)
PdfDocument.Open()
'Create tempfile to hold the HTML:
'Dim tempFile As String = Path.GetTempFileName()
'Using tempwriter As New StreamWriter(tempFile, False)
' tempwriter.Write(GridStyle)
'End UsingDim _xmlr As New System.Xml.XmlTextReader(New StringReader(GridStyle))
'Parse the HTML into the document
iTextSharp.text.html.HtmlParser.Parse(PdfDocument, _xmlr)
'Cleanup
PdfDocument.Close()
writer.Close()
'Delete the tempfile:
'File.Delete(tempFile)
writer =
Nothing
PdfDocument =
Nothing
HttpContext.Current.Response.[End]()
End Sub
can you help me or give me another solution
thanx