I am creating a report in PHP using mPDF Library. Till now the output is saved as a pdf file which I need to print out manually by opening the auto downloaded file.
What I need is as soon as I click on Print button on my PHP Web page, mPDF should create the output and immediately print the document using default printer. I even donot need any intermediate dialog box that would again get a confirmation to print. Simply, clicking on PHP based web page button should send the print command to the default printer.
Below is my code:
include("\mpdf\mpdf.php");
$mpdf=new mPDF('','A4');
$mpdf->WriteHTML($a);
$mpdf->Output('r.pdf', 'D');
What else I can do to achieve what I need?
What I have tried:
I have tried the following code:
include("\mpdf\mpdf.php");
$mpdf=new mPDF('','A4');
$mpdf->WriteHTML($a);
$mpdf->SetJS('this.print();');
$mpdf->Output();
This solution comes up with two problems:
1. It still opens a dialog for print confirmation.
2. It opens the print preview and the dialog box in my current tab which means that on clicking print, I cannot get the same interface on which I was working before clicking Print. For that, I have to click on back button on the browser which is not a good solution.