如何在dom pdf中包含外部样式表 [英] How to include the external style sheet in dom pdf
问题描述
我正在使用Dompdf在php中生成报告。我无法包含相同的外部样式表...
I am using Dompdf for the report generation in the php. I am not able to include the external style sheet for the same...
我使用的代码类似于以下内容:
The code I am using is similar to the following:
<?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文件。
Please let me know how to include the external css file..
推荐答案
$ dompdf-> set_base_path()
不在您指定CSS的位置。该方法使您有机会定义附加到文档中相对路径的基本路径。
$dompdf->set_base_path()
isn't where you specify your CSS. That method gives you the opportunity to define a base path that is appended to relative paths in the document.
您的CSS应该是您提供给dompdf的HTML的一部分。类似于以下内容:
Your CSS should be part of the HTML you feed to dompdf. Something like the following:
<?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浏览器。您可以像使用任何网络浏览器一样向其提供有效的HTML文档。
Think of dompdf as a web browser that renders to PDF instead of a screen. You feed it a valid HTML document just like you would any web browser.
这篇关于如何在dom pdf中包含外部样式表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!