Mpdf库不会在浏览器中输出PDF,而总是下载

时间:2019-12-04 16:13:37

标签: mpdf

我不确定为什么它无法在任何浏览器中打开并始终下载。

<?php
use Mpdf\Mpdf;

require __DIR__ . '/vendor/autoload.php';

// Grab variables
$fname   = $_POST[ 'fname' ];
$lname   = $_POST[ 'lname' ];
$email   = $_POST[ 'email' ];
$phone   = $_POST[ 'phone' ];
$message = $_POST[ 'message' ];

$filename = 'invoice.pdf';

ob_clean();
header('Content-type: application/pdf');
header('Content-Disposition: inline; filename="' . $filename . '"');
header('Content-Transfer-Encoding: binary');
header('Accept-Ranges: bytes');

$mpdf = new Mpdf();

//
// create pdf
$data = '<h1>' . $fname . ' ' . $lname . '\'s Details</h1>';
$data .= '<table>';
$data .= '<tr><th>First Name: </th><td>' . $fname . '</td><td class="price">220,25kr</td></tr>';
$data .= '<tr><th>Last Name: </th><td>' . $lname . '</td><td class="price">1257,50kr</td></tr>';
$data .= '<tr><th>Email: </th><td>' . $email . '</td><td class="price">25,35kr</td></tr>';
$data .= '<tr><th>Phone: </th><td>' . $phone . '</td><td class="price">532,00kr</td></tr>';

if ($message) {
    $data .= '<tr><th>Message: </th><td colspan="2">' . $message . '</td></tr>';
}

$data .= '<tr><th colspan="2">Total </th><td class="price">7,251,90kr</td></tr>';
$data .= '</table>';


// write pdf
$stylesheet = file_get_contents('invoice.css');
$mpdf->shrink_tables_to_fit = 1;
$mpdf->WriteHTML($stylesheet, 1);
$mpdf->WriteHTML($data);

// output to browser
$mpdf->Output($filename, 'I');

ob_end_flush();
?>

1 个答案:

答案 0 :(得分:0)

这是一个接管行为的Download Manager扩展。我已经禁用了,一切正常。