如何使用 dompdf 在浏览器选项卡上向 PDF 添加元标题?

在使用 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));


一只名叫tom的猫
浏览 110回答 1
1回答

森林海

看了很多之后,我找到了方法:$dompdf->add_info('Title',&nbsp;'Your&nbsp;meta&nbsp;title');我花了一些时间才找到答案,所以我相信这会对其他人有所帮助。
打开App,查看更多内容
随时随地看视频慕课网APP