在使用 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 關注
- 124 瀏覽
添加回答
舉報
0/150
提交
取消