简体   繁体   中英

PHPDesktop and mPDF, print forces to save instead of showing print dialog

I have written code for printing report using mdf library in PHP as below:

include("..\mpdf\mpdf.php");
$mpdf=new mPDF('','A4');
$mpdf->WriteHTML($a);
$mpdf->SetJS('this.print();');
$mpdf->Output();
exit;

When I use this applicaiton, things go fine. I directly get print dialog box and there are no PHP warnings too. But when the same application is executed under PHPDesktop, it shows pdf save dialog instead of showing print dialog and also shows the warning:

session_start(): Cannot send session cache limiter - headers already sent

although I have already used the below code on the top of every php page:

OB_START();
if(session_status()!=PHP_SESSION_ACTIVE ||  session_status() == PHP_SESSION_NONE)
    session_start();

I want to open the print dialog box in PHPDesktop also. Please provide some solution.

UPDATE

I have downloaded phpdesktop-chrome-57.0-rc-php-7.1.3 from Github. Also, I have downloaded php_printer.dll from Github. Version is php_printer-php5.6.30 I have placed the dll in every possible folder and also have added it as an extension to the php.ini file of PHPDesktop project directory. Now, it tries to show the preview but says: "Failed to load PDF document"

Any early output will cause header errors. Things to look for are echoes that happen before your header calls, or actual output, be it html or even just white space. Errors and warnings if displayed also mess things up.

This sounds like you have display_errors turned on in your ini.

Turn off display_errors in your ini, otherwise warnings and notices will screw your headers.

For the best error logging experience, set error_reporting to -1 , turn display_errors off, and set a custom error_log . Then in your terminal, type tail -f /path/to/error_log . Your notices, warnings and errors will now scroll past in real time, without distorting your web page's display.

Once no warnings or notices are appearing, the headers will be sent correctly and your application should work as it usually does.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM