在使用 domppdf 生成 PDF 时,我一直无法找到在浏览器选项卡上显示标题(如元标题)的方法。
在一些帖子中,他们建议将其添加到 HTML 代码中:
<html>
<head><title> My Title </title>
</head>
<body>
/** PDF Content **/
</body>
Run Code Online (Sandbox Code Playgroud)
但是,也许是由于我正在使用的版本,但添加这些标签会破坏我的代码,并且 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));
Run Code Online (Sandbox Code Playgroud)
经过多方查找,我找到了方法:
$dompdf->add_info('Title', 'Your meta title');
Run Code Online (Sandbox Code Playgroud)
我花了一些时间才找到答案,所以我相信这对其他人会有帮助。
| 归档时间: |
|
| 查看次数: |
3071 次 |
| 最近记录: |