title: Using PHP DOMPDF and AJAX to download a PDF File
body: <p>I have this PHP File called print.php:</p>
  
  <pre><code>&lt;?php
  require_once("modules/pdf/dompdf_config.inc.php");
  $html = $_POST["toRender"];
  $number = $_POST["number"];
  $dompdf = new DOMPDF();
  $dompdf-&gt;load_html($html);
  $dompdf-&gt;render();
  $dompdf-&gt;stream($number.".pdf");
  </code></pre>
  
  <p>As you can see, the HTML and a Number are received via POST.</p>
  
  <p>The JavaScript file looks like this:</p>
  
  <pre><code> $("#btnViewPDF").click(function() {
  
          var theHtml = $("#printable").html();
          var theNumber = $("#invoiceNumber").val();
  
          $.ajax({
              type : "post",
              url  : "views/print.php",
              data : {toRender : theHtml, number : theNumber},
              beforeSend: function() {
                  $(".ajax-loader-bg").fadeIn();
              }
          }).always(function() {
              $(".ajax-loader-bg").fadeOut();
          });
          return false;
      });
  </code></pre>
  
  <p>Basically it takes all the content inside a DIV called 'printable' but what I want next is the PDF that has been generated in print.php to be displayed, I haven't been able to figure out how can I make this.</p>
  
  <p>I've made it work when I generate test HTML inside print.php and then I type in the url mysite.com/print.php ... it renders the PDF and allows me to download it or see it in another browser tab. </p>
  
  <p>How can I achieve this via AJAX? </p>