为什么dompdf不允许为字符串分配颜色?

时间:2014-04-07 07:16:39

标签: php colors dompdf

我想给我的字符串添加颜色,但是dompdf不允许我。这是我的HTML代码:

 <style type="text/css">
            .red{
                color:#574595;
            }
         </style>

            <div style="color:#574595;">asdfsdfsd</div><br>
            <font color="red">TRALALAL</font><br>
            <div class="red">TRALALAL</div><br>

我尝试了3种可能的方法,但两种方法都不起作用。我该如何管理? 这是我的完整代码:

<?php
    ini_set("gd.jpeg_ignore_warning", 1);
    set_include_path(get_include_path() . PATH_SEPARATOR . "dompdf");
    require_once('dompdf/dompdf_config.inc.php');
    $category = $_GET['c'];
    $dompdf = new DOMPDF();
    $html = 
    '<html>
        <head>
        <style type="text/css">
                    .red{
                        color:#574595;
                    }
                 </style>
        </head>

        <body>


                    <div style="color:#574595;">asdfsdfsd</div><br>
                    <font color="red">TRALALAL</font><br>
                    <div class="red">TRALALAL</div><br>

        </body>
        </html>';
    $dompdf->load_html($html);
    $dompdf->render();

    $output = $dompdf->output();
    file_put_contents("pdf_generated/file.pdf", $output);

    header("Location: http://acros.netlogiq.info/pdf_generated/file.pdf");
?>

这就是结果: enter image description here

2 个答案:

答案 0 :(得分:0)

在这里试过你的代码:http://www.digitaljunkies.ca/dompdf/examples.php

HTML:

<html>
<head>
<style type="text/css">
            .red{
                color:#574595;
            }
         </style>
</head>

<body>


            <div style="color:#574595;">asdfsdfsd</div><br>
            <font color="red">TRALALAL</font><br>
            <div class="red">TRALALAL</div><br>

</body>
</html>

它的工作,我得到了红色字体。检查一次配置设置。

编辑:

DOMPDF PHP代码:

<?php
require_once "../dompdf_config.inc.php";
ini_set("gd.jpeg_ignore_warning", 1);
$dompdf = new DOMPDF();
    $html = 
    '<html>
        <head>
        <style type="text/css">
                    .red{
                        color:#574595;
                    }
                 </style>
        </head>

        <body>


                    <div style="color:#574595;">asdfsdfsd</div><br>
                    <font color="red">TRALALAL</font><br>
                    <div class="red">TRALALAL</div><br>

        </body>
        </html>';
    $dompdf->load_html($html);
    $dompdf->render();
$dompdf->stream("dompdf_out.pdf", array("Attachment" => false));
exit(0);
?>

我试过这个,我得到了字体颜色。检查您的配置。配置UI可以在这里显示:localhost / dompdf / www / setup.php

(我希望你有相同的文件夹结构)

答案 1 :(得分:-1)

看看这是一个例子:

http://jsfiddle.net/C6bQf/

代码:

<style>
    .red{
        color: red;
}
</style>
<div style="color: red;">asdfsdfsd</div><br>
<font color="red">TRALALAL</font><br>
<div class="red">TRALALAL</div><br>

将文件另存为HTML。