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?
Here is the code I have
//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;
}
});
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 window.print() there?
One easy approach for this is to put the PDF file in a new iFrame.
Then you can print the complete content inside the iframe using
window.print();function.Now call
window.print();function when you want to print your pdf.