title: The document has no pages exception while converting sharepoint page to pdf
body: <p>Using itextSharp and sharepoint visual webpart coding I am converting current aspx page to pdf but I am not to able convert. I have found that issue is in this line "this.Page.RenderControl(hw)" If I comment this line I get "The document has no pages" exception and If I uncomment this line I get "A page can have only one server-side Form tag" error. How can I handle this? Pls somebody help me pls..</p>
  
  <pre><code>protected void BtnSubmit_Click(object sender, EventArgs e)
  {
   try
           {
              HttpContext.Current.Response.ContentType = "application/pdf";
              HttpContext.Current.Response.AddHeader("content-disposition", "attachment;filename=UserDetails.pdf");
              HttpContext.Current.Response.Cache.SetCacheability(HttpCacheability.NoCache);
              StringWriter sw = new StringWriter(); 
              HtmlTextWriter hw = new HtmlTextWriter(sw); 
  
              //this.Page.RenderControl(hw);
  
              StringReader sr = new StringReader(sw.ToString());
              Document pdfDoc = new Document(PageSize.A4, 10f, 10f, 100f, 0.0f);
              HTMLWorker htmlparser = new HTMLWorker(pdfDoc);
              PdfWriter.GetInstance(pdfDoc, HttpContext.Current.Response.OutputStream);
              pdfDoc.Open();
              htmlparser.Parse(sr);
              pdfDoc.Close();
              HttpContext.Current.Response.Write(pdfDoc);
              HttpContext.Current.Response.End();
  
  
              }
          catch (Exception exp)
              {
  
  
              } 
   }
  
  protected override void Render(HtmlTextWriter writer)
      {
          // Ensure that the control is nested in a server form.
          if (Page != null)
          {
              Page.VerifyRenderingInServerForm(this);
          }
          base.Render(writer);
     }
  </code></pre>