我正在使用DOMPDF(v 0.5.2)将html页面转换为pdf文件.
PHP脚本运行后(如预期的那样)显示pdf文件,但没有样式应用于任何内容.据我所知,浮动属性不适用于DOMPDF,所以我必须做一些工作来解决这个问题,但是甚至没有应用字体样式.
我尝试了包括样式的所有三种方法:附加样式表,
<link href="styles.css" rel="stylesheet" type="text/css">
Run Code Online (Sandbox Code Playgroud)
在标题中写样式,
<style>...</style>
Run Code Online (Sandbox Code Playgroud)
和内联样式.
<div class="..." style="...">
Run Code Online (Sandbox Code Playgroud)
用于创建pdf的php文件看起来像这样......
<?php
ob_start();
?>
<html>
<head>
<link href="flhaha.css" rel="stylesheet" type="text/css">
</head>
<body>
... content (divs, etc)
</body>
</html>
<?php
require_once("../../scripts/dompdf/dompdf_config.inc.php");
$dompdf = new DOMPDF();
$dompdf->load_html(ob_get_clean());
$dompdf->render();
$dompdf->stream('test.pdf');
?>
Run Code Online (Sandbox Code Playgroud)
内容中的图像可以正常加载并在pdf打开时正确显示,但仍然没有样式.
提前致谢!
编辑#1:上面的标签是"风格",而不是"风格".修正了错字.