title: Generating PDF via AJAX using mpdf
body: <p>I'm using the <a href="https://github.com/mpdf/mpdf" rel="nofollow noreferrer">mpdf library</a> to generate a PDF of user-generated html. I can get the PDF to save to the server successfully, but I want the PDF to open in the browser for the user. I've tried using mpdf's output options to open the file in the browser or to prompt a download, but neither happens when I use AJAX to send the html data to the script.</p>
  
  <p>Here's my AJAX:</p>
  
  <pre><code>$('#save').click(function() {
  
          var shelf_clone = $('#shelf').clone();
          var shelf = shelf_clone.prop('outerHTML'); 
  
          $.ajax({
              type: "POST",
              url: "pdf.php",
              data: { html:shelf },
              success: function(response)
              {
                  $('#status').html('File Saved Successfully');
              },
          })
  
      });
  </code></pre>
  
  <p>Here's my PDF-generating script:</p>
  
  <pre><code>&lt;?php
  
  include_once('/mpdf/mpdf.php');
  
  $html = $_POST['html'];
  
  $mpdf=new mPDF();
  $stylesheet = file_get_contents('css/print.css');
  $mpdf-&gt;WriteHTML($stylesheet,1);
  $mpdf-&gt;WriteHTML($html,2);
  $mpdf-&gt;Output('shelf.pdf', I);
  
  exit;
  
  ?&gt;
  </code></pre>
  
  <p>I'm using AJAX so that the PDF can be created without having to navigate away from the page. Is there an error in my code or should I be using a different approach? </p>