php – 如何在dom pdf中包含外部样式表
发布时间:2020-12-13 17:46:05 所属栏目:PHP教程 来源:网络整理
导读:我正在使用Dompdf来生成php中的报告.我无法将相同的外部样式表包括在内…… 我使用的代码类似于以下内容: ?phprequire_once "dompdf/dompdf_config.inc.php";$dompdf = new DOMPDF();$html ="table tr td class='abc'testing table/td /tr tr td class='def
我正在使用Dompdf来生成php中的报告.我无法将相同的外部样式表包括在内……
我使用的代码类似于以下内容: <?php require_once "dompdf/dompdf_config.inc.php"; $dompdf = new DOMPDF(); $html =" <table> <tr > <td class='abc'>testing table</td> </tr> <tr> <td class='def'>Testng header</td> </tr> </table>"; $dompdf->load_html($html); $dompdf->render(); $dompdf->set_base_path('localhost/exampls/style.css'); $dompdf->stream("hello.pdf"); ?> 请告诉我如何包含外部css文件.. 解决方法
$dompdf-> set_base_path()不是指定CSS的地方.该方法使您有机会定义附加到文档中相对路径的基本路径.
您的CSS应该是您提供给dompdf的HTML的一部分.类似于以下内容: <?php require_once "dompdf/dompdf_config.inc.php"; $dompdf = new DOMPDF(); $html =" <html> <head> <link type="text/css" href="localhost/exampls/style.css" rel="stylesheet" /> </head> <body> <table> <tr > <td class='abc'>testing table</td> </tr> <tr> <td class='def'>Testng header</td> </tr> </table> </body> </html>"; $dompdf->load_html($html); $dompdf->render(); $dompdf->set_base_path('localhost/exampls/style.css'); $dompdf->stream("hello.pdf"); ?> 将dompdf视为呈现为PDF而非屏幕的Web浏览器.您可以像使用任何Web浏览器一样为其提供有效的HTML文档. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |