huge data export in pdf itextsharp RRS feed

  • Question

  • User639567535 posted

    I try to export data in PDF there is huge data so when i export  .. I try below code

            Private Sub ExportGridToPDF()
                Dim GridView1 As New GridView 
                Using myMemoryStream As New MemoryStream()
                    Dim myDocument As New iTextSharp.text.Document(iTextSharp.text.PageSize.A1, 10.0F, 10.0F, 10.0F, 0.0F)
                    ' Dim myDocument As New iTextSharp.text.Document()
                    Dim myPDFWriter As PdfWriter = PdfWriter.GetInstance(myDocument, myMemoryStream)
                    ' Add to content to your PDF here...
                    Dim sw As New StringWriter()
                    Dim hw As New HtmlTextWriter(sw)
                    GridView1.AllowPaging = False
                    ' We're done adding stuff to our PDF.
                    Dim content As Byte() = myMemoryStream.ToArray()
                    ' Write out PDF from memory stream.
                    Using fs As FileStream = File.Create("Report_PDF.pdf")
                        fs.Write(content, 0, CInt(content.Length))
                    End Using
                End Using
        End Sub

    when i run this shows an error

    System.InvalidCastException: Unable to cast object of type 'System.Web.UI.HtmlTextWriter' to type 'iTextSharp.text.IElement'.

    on this line

    I use memory stream because of huge data when i use code without memory stream then shows an error Out of Memory exception so i use memory stream and now this shows different error

    Wednesday, September 13, 2017 11:39 AM

All replies