title: Trying to convert a gridview into a PDF document
body: <p>Basic principle is that I am trying to take a GridView and turn it into a PDF document. The GridView includes controls like checkboxes and some css classes with some colouring.</p>
  <p>I have tried putting this together, but I think I am misunderstanding how something works and now hit a dead end. At present it all compiles and runs, but when you try and open the returned PDF it says it fails to load. The returned file is 1KB in size, so I am guessing that it isn't actually a valid PDF.</p>
  <p>I am using iText7 and htmlPDF, with my code looking like this.</p>
  <pre><code>Protected Sub ExportToPDF(sender As Object, e As ImageClickEventArgs)
      Using sw As New StringWriter()
          Using hw As New HtmlTextWriter(sw)
              Response.ContentType = &quot;application/pdf&quot;
              Response.AddHeader(&quot;content-disposition&quot;, &quot;attachment;filename=GridViewExport.pdf&quot;)
              Response.Cache.SetCacheability(HttpCacheability.NoCache)
  
              gvCSC.DataBind()
              gvCSC.RenderControl(hw)
  
              Dim pdfWriter As New PdfWriter(Response.OutputStream)
              Dim pdfDoc As New PdfDocument(pdfWriter)
              Dim sr As New StringReader(sw.ToString)
              pdfDoc.SetDefaultPageSize(New PageSize(PageSize.A4.Rotate))
              Dim doc As Document = HtmlConverter.ConvertToDocument(sr.ToString, pdfDoc, New ConverterProperties)
  
              Response.End()
  
              pdfDoc.Close()
          End Using
      End Using
  End Sub
  </code></pre>
  <p>I am hoping that I am just being stupid as I've not used iText7 before and it just needs someone to point out the obvious for me. Any help in solving this will be appreciated.</p>