How do I get WKHTMLTOPDF to execute via PHP?

后端 未结 7 1862
孤街浪徒
孤街浪徒 2020-11-29 00:28

This has been asked to some degree before but there are no solutions or accepted answers and I\'d like to try and be more comprehensive in my question so:

I\'m tryin

相关标签:
7条回答
  • 2020-11-29 01:31

    You may want to set up proper headers and set it to application/pdf as well as setting it to inline so that people can see it in their browsers (almost every recent browser supports this) and save it if they want. This is the code that I'm using:

    exec("/usr/local/bin/wkhtmltopdf ../uploads/test.pdf");
    $file = "../uploads/test.pdf";
    $pdf = file_get_contents("../uploads/test.pdf");
    
    header('Content-Type: application/pdf');
    header('Cache-Control: public, must-revalidate, max-age=0'); // HTTP/1.1
    header('Pragma: public');
    header('Expires: Sat, 26 Jul 1997 05:00:00 GMT'); // Date in the past
    header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
    header('Content-Length: '.strlen($pdf));
    header('Content-Disposition: inline; filename="'.basename($file).'";');
    ob_clean(); 
    flush(); 
    echo $pdf;
    ?>
    
    0 讨论(0)
提交回复
热议问题