Click here to Skip to main content
15,887,676 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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:

PHP
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:

PHP
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.
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900