title: Export aspx web pages to pdf and download
body: <p>I am having some problem when trying to export an aspx page as pdf and download them. Here is the codes:</p>
  
  <pre><code>    protected void Button1_Click(object sender, EventArgs e)
      {
          string url = Request.Url.AbsoluteUri;
          using (StreamReader reader = new StreamReader(Server.MapPath(url)))
          {
              String line = reader.ReadToEnd();
              Text2PDF(line);
          }
      }
  
      protected void Text2PDF(string PDFText)
      {
          //HttpContext context = HttpContext.Current;
          StringReader reader = new StringReader(PDFText);
  
          //Create PDF document 
          Document document = new Document(PageSize.A4);
          HTMLWorker parser = new HTMLWorker(document);
  
          string PDF_FileName = Server.MapPath("MyFirstPdf.pdf");
          PdfWriter.GetInstance(document, new FileStream(PDF_FileName, FileMode.Create));
          document.Open();
  
          try
          {
              parser.Parse(reader);
          }
          catch (Exception ex)
          {
              //Display parser errors in PDF. 
              Paragraph paragraph = new Paragraph("Error!" + ex.Message);
              Chunk text = paragraph.Chunks[0] as Chunk;
              if (text != null)
              {
                  text.Font.Color = BaseColor.RED;
              }
              document.Add(paragraph);
          }
          finally
          {
              document.Close();
              DownLoadPdf(PDF_FileName);
          }
      }
      private void DownLoadPdf(string PDF_FileName)
      {
          WebClient client = new WebClient();
          Byte[] buffer = client.DownloadData(PDF_FileName);
          Response.ContentType = "application/pdf";
          Response.AddHeader("content-length", buffer.Length.ToString());
          Response.BinaryWrite(buffer);
      }
  </code></pre>
  
  <p>However, when I click the button, nothing happens. The browser does not prompt me to download as well. I wonder why. Thanks in advance.</p>