在使用 domppdf 生成 PDF 時(shí),我一直無(wú)法找到在瀏覽器選項(xiàng)卡上顯示標(biāo)題(如元標(biāo)題)的方法。在一些帖子中,他們建議將此添加到 HTML 代碼中:<html><head><title> My Title </title></head><body>/** PDF Content **/</body>但是,也許是因?yàn)槲沂褂玫陌姹?,但添加這些標(biāo)簽會(huì)破壞我的代碼并且 dompdf 會(huì)返回一個(gè)長(zhǎng)錯(cuò)誤。我只有身體,而且效果很好。不幸的是,我無(wú)法升級(jí)我的 dompdf 版本,所以我正在嘗試尋找另一種解決方案。我不認(rèn)為使用 PHP 標(biāo)頭是可能的,但我愿意接受建議。到目前為止我有這個(gè):$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貢獻(xiàn)2011條經(jīng)驗(yàn) 獲得超2個(gè)贊
看了很多之后,我找到了方法:
$dompdf->add_info('Title', 'Your meta title');
我花了一些時(shí)間才找到答案,所以我相信這會(huì)對(duì)其他人有所幫助。
- 1 回答
- 0 關(guān)注
- 122 瀏覽
添加回答
舉報(bào)
0/150
提交
取消