Mpdf 库不会在浏览器中输出 PDF 而总是下载
Mpdf library won't output the PDF in browser rather always download
我不确定为什么它不能在任何浏览器中打开并总是下载它。
<?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();
?>
接管该行为的是下载管理器扩展程序。我已禁用,一切正常。
我不确定为什么它不能在任何浏览器中打开并总是下载它。
<?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();
?>
接管该行为的是下载管理器扩展程序。我已禁用,一切正常。