在使用 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 Browserheader("Content-type:application/pdf");header("Content-Disposition: attachment; filename=$fileName.pdf'");$dompdf->stream($fileName,array('Attachment'=>0));
1 回答

森林海
TA贡献2011条经验 获得超2个赞
看了很多之后,我找到了方法:
$dompdf->add_info('Title', 'Your meta title');
我花了一些时间才找到答案,所以我相信这会对其他人有所帮助。
- 1 回答
- 0 关注
- 109 浏览
添加回答
举报
0/150
提交
取消