title: Using AJAX and PHP to output PDF
body: <p>The way my web app is supposed to work is that the user fills out a form and then the AJAX sends the form data to a PHP file that generates a PDF (using xpdf). Then the generated PDF should be available for download on the HTML page with the AJAX. </p>
  
  <p>If I open pdf.php directly in the browser it works fine. However I need to figure out how to connect it with the AJAX so that it sends the generated PDF back to the AJAX and the user can simply click a button on the page to download it. </p>
  
  <p>AJAX:</p>
  
  <pre><code>$.ajax({
      url: 'pdf.php',
      type: 'POST',
      data: pdfData
  })
  .done(function(response){
  });
  </code></pre>
  
  <p>pdf.php:</p>
  
  <pre><code>&lt;?php 
  include('fpdf.php');
  include('fpdi.php'); 
  
  // initiate FPDI 
  $pdf =&amp; new FPDI(); 
  // add a page 
  $pdf-&gt;AddPage();
  ...
  $pdf-&gt;Output('address.pdf', 'D'); 
  ?&gt;
  </code></pre>