我正在使用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 文档。
关于php - 如何在dom pdf中包含外部样式表,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/19805148/