CSS无法与DOMPDF一起使用 [英] CSS not working with DOMPDF
问题描述
我正在使用DOMPDF(v 0.5.2)将html页面转换为pdf文件.
I am using DOMPDF (v 0.5.2) to convert an html page to a pdf file.
pdf文件在PHP脚本运行后出现(如预期的那样),但是没有样式应用于任何内容.据我所知,float属性不适用于DOMPDF,因此我必须做一些工作来解决该问题,但是甚至不会应用字体样式.
The pdf file appears after the PHP script has run (as expected), but no styles are applied to any of the content. As far as I can find, the float property does not work with DOMPDF, so I have to do some work to get around that, but not even the font styles are being applied.
我尝试了包括样式在内的所有三种方法: 附加样式表
I have tried all three methods of including styles: attaching a style sheet,
<link href="styles.css" rel="stylesheet" type="text/css">
在标题中书写样式
<style>...</style>
和内联样式.
<div class="..." style="...">
用于创建pdf的php文件如下所示...
The php file to create the pdf looks like this...
<?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');
?>
内容中有一张图片可以很好地加载,并且在打开pdf时可以正确显示,但是仍然没有样式.
There is an image within the content that loads fine and is displayed properly when the pdf opens, but still no styles.
提前谢谢!
编辑#1:上面的标签应为样式",而不是样式".纠正了错字.
Edit #1: The tags above were meant to be "style", not "styles". Have fixed the typo.
推荐答案
dompdf v0.5.x不支持浮点数. v0.6.0可以,尽管它仍然是实验性功能,必须在配置中启用.测试完您的文档后,我可以说dompdf不能很好地处理它.如果您想使用dompdf,则可以考虑使用表格,因为您的文档本质上是表格形式的.
dompdf v0.5.x does not support floats. v0.6.0 does, though it is still an experimental feature that has to be enabled in the configuration. After testing your document I can say that dompdf doesn't handle it very well. If you want to stick with dompdf you might consider tables since your document is somewhat tabular in nature.
这篇关于CSS无法与DOMPDF一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!