我正在使用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");
?>
Run Code Online (Sandbox Code Playgroud)
请告诉我如何包含外部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");
?>
Run Code Online (Sandbox Code Playgroud)
将dompdf视为呈现为PDF而非屏幕的Web浏览器.您可以像使用任何Web浏览器一样为其提供有效的HTML文档.
dompdf 支持一些 CSS 2.1 选择器语法。dompdf 还支持具有多个类属性 ( e.g. <p class="red bold">foo</p> matches p.red and p.bold) 的元素。
请注意,dompdf 中的 CSS 选择器区分大小写(例如,.foo不会匹配<div class="FOO">bar</div>)
阅读http://code.google.com/p/dompdf/wiki/CSSCompatibility或 Git https://github.com/dompdf/dompdf/wiki/CSSCompatibility