I am getting error below when i try to export GridView data to PDF.
An exception of type 'System.IO.IOException' occurred in itextsharp.dll but was not handled in user code
Additional information: The document has no pages.
Protected Sub ExportToPDF(ByVal sender As Object, ByVal e As EventArgs) Handles Button3.Click, Button3.Click, Button3.Click
Using sw As New StringWriter()
Using hw As New HtmlTextWriter(sw)
'To Export all pages
gvCustomers.AllowPaging = False
Dim strConnString As String = ConfigurationManager.ConnectionStrings("SLISConnectionString").ConnectionString
Using con As New SqlConnection(strConnString)
Using cmd As New SqlCommand("SELECT * FROM Postserialnumberaccreg")
Using sda As New SqlDataAdapter()
cmd.Connection = con
sda.SelectCommand = cmd
Using dt As New DataTable()
sda.Fill(dt)
gvCustomers.DataSource = dt
gvCustomers.DataBind()
If dt.Rows.Count > 1 Then
' gvCustomers.RenderControl(hw)
Dim sr As New StringReader(sw.ToString())
Dim pdfDoc As New Document(PageSize.A2, 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.NewPage()
pdfDoc.Close()
Response.ContentType = "application/pdf"
Response.AddHeader("content-disposition", "attachment;filename=GridViewExport.pdf")
Response.Cache.SetCacheability(HttpCacheability.NoCache)
Response.Write(pdfDoc)
Response.[End]()
Else
Dim time23 As String = "Specify Date Range and Click on Generate"
Dim script23 As String = "window.onload = function() { askConfirm('" & time23 & "'); };"
ClientScript.RegisterStartupScript(Me.GetType(), "askConfirm", script23, True)
Exit Sub
End If
End Using
End Using
End Using
End Using
End Using
End Using
End Sub