在使用 domppdf 生成 PDF 时,我一直无法找到在浏览器选项卡上显示标题(如元标题)的方法。
在一些帖子中,他们建议将此添加到 HTML 代码中:
<html>
<head><title> My Title </title>
</head>
<body>
/** PDF Content **/
</body>
但是,也许是因为我使用的版本,但添加这些标签会破坏我的代码并且 dompdf 会返回一个长错误。我只有身体,而且效果很好。
不幸的是,我无法升级我的 dompdf 版本,所以我正在尝试寻找另一种解决方案。我不认为使用 PHP 标头是可能的,但我愿意接受建议。
到目前为止我有这个:
$dompdf = new Dompdf();
ob_start();
include("pdf_HTML.php");
$fileName = "download.pdf";
$content = ob_get_clean();
$dompdf->loadHtml($content);
// (Optional) Setup the paper size and orientation
$dompdf->setPaper('Letter', 'portrait');
// Render the HTML as PDF
$dompdf->render();
// Output the generated PDF to Browser
header("Content-type:application/pdf");
header("Content-Disposition: attachment; filename=$fileName.pdf'");
$dompdf->stream($fileName,array('Attachment'=>0));
森林海