title: How can I print a PDF fetched via an ajax request?
body: <p>I'm having a form that once submitted, the PHP generates a PDF file and sends it to the client.  Everything works fine so far. What I'm having trouble with is that I need to trigger window.print() on the window containing the received pdf. Is there a way to make the printing wizard appear for the received pdf file?</p>
  
  <p>Here is the code I have</p>
  
  <pre><code>//The #options is a form that once submitted is sends the requested PDF to the browser
  $('#options').on('submit', function(e){
  
      if($(this).find('[name="action"]').val() == 'print')
      {
          var url = $(this).attr('action') || document.URL;
          e.preventDefault();
          $.post(url, $(this).serializeArray(),function(pdf){
              // Open the printing wizard for the requested document
          });
      }
      else
      {
          // The PDF is displayed normally
          return true;
      }
  
  });
  </code></pre>
  
  <p>I'm not even sure if what I want to do is possible. Is is possible for example to open the PDF in a new tab and call <code>window.print()</code> there?</p>