title: Trying to display a PDF file generated with iTextSharp in ASP.NET MVC
body: <p>I have an ajax method .....</p>
  
  <pre><code> function downloadPDF() {
          var elem = $('#actionPlanDetails');
          elem.find("button").hide();
          elem.find("iframe").hide();
          elem.find("input[type='button']").hide();
  
          html2canvas(elem[0], {
              onrendered: function (canvas) {
                  var result = canvas.toDataURL();
                  var base64 = result.split(',')[1];
                  elem.find("button").show();
                  elem.find("iframe").show();
                  elem.find("input[type='button']").show();
                  $.ajax({
                      beforeSend: function () {
                          $.blockUI({ message: $('#waitMessage') });
                      },
                      url: "/ActionPlan/UploadPDF",
                      type: 'POST',
                      data: { pdfStr: base64 },
                      dataType: 'image/jpeg',
                      success: function (result) {
                          console.log('PDF');
                      },
                      complete: function () {
                          $.unblockUI();
                      }
                  });
              }
          });
      }
  </code></pre>
  
  <p>...which uses html2canvas.js to get a screen image and send the bytes to an MVC action method....</p>
  
  <pre><code>[HttpPost]
          public ActionResult UploadPDF(string pdfStr)
          {
              byte[] pdf = Convert.FromBase64String(pdfStr);
              int fileLength = pdf.Length;
  
              Document doc = new Document();
              string pdfpath = Server.MapPath("../Content/pdfs");
              try
              {
                  PdfWriter.GetInstance(doc, new FileStream(pdfpath + "/Plan.pdf", FileMode.Create));
                  doc.Open();
                  Image planImg = Image.GetInstance(pdf);
                  doc.Add(planImg);
              }
              catch (Exception ex)
              {
  
              }
              finally
              {
                  //doc.Close();
              }
              return File("~/Content/pdfs/Plan.pdf", "application/pdf");
          }
  </code></pre>
  
  <p>...which converts the passed string to a byte array, and uses iTextSharp to create a document, append it to the PDF document and write it to the Content subdirectory. </p>
  
  <p>The issue comes in that, after writing the PDF file i <em>also want it to pop up in a window on action return</em>, as I've often seen the Controller.File() method do. But nothing happens. The PDF saves fine in the content folder but nothing pops up when the action returns. </p>
  
  <p>looking at was is in the response in fiddler I just see a bunch of bytes, instead of a PDF, so I think maybe i'm leaving out some configuration/metadata, but I can't find much on this situation in the docs.</p>