title: Converting Asp.net page to pdf with Itextsharp (XMLWorker) returning damaged/blank pdf
body: <p>Not sure if I skipped a step in my code, I am using ItextSharp version 5.5.1 and XML Worker version 5.5.1. The doc.Close throws an exception "the document has no pages", but I watched sw.toString (it has the html content).</p>
  
  <pre><code>private void ExporttoPDF()
          {
              HttpContext.Current.Response.Clear();
              HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment;filename=RequestSummaryReport.pdf");
              HttpContext.Current.Response.Charset = "";
              HttpContext.Current.Response.ContentType = "application/pdf";
  
              StringWriter sw = new StringWriter();
              HtmlTextWriter htw = new HtmlTextWriter(sw);         
  
              var doc = new Document(PageSize.A3, 45, 5, 5, 5);
              PdfWriter writer = PdfWriter.GetInstance(doc, Response.OutputStream);
  
              doc.Open();
  
              HtmlPipelineContext htmlContext = new HtmlPipelineContext(null);
              htmlContext.SetTagFactory(Tags.GetHtmlTagProcessorFactory());
              ICSSResolver cssResolver = XMLWorkerHelper.GetInstance().GetDefaultCssResolver(false);
  
              IPipeline pipeline = new CssResolverPipeline(cssResolver, new HtmlPipeline(htmlContext, new PdfWriterPipeline(doc, writer)));
  
              XMLWorker worker = new XMLWorker(pipeline, true);
              XMLParser xmlParse = new XMLParser(true, worker);
  
              pnlReport.RenderControl(htw);
              StringReader sr = new StringReader(sw.ToString());
              xmlParse.Parse(sr);
              xmlParse.Flush();
              doc.Close();
              Response.Write(doc);
          }
  </code></pre>