【问题标题】:why dompdf doesn't allow to assign a color to a string?为什么 dompdf 不允许为字符串分配颜色?
【发布时间】:2014-04-07 07:16:39
【问题描述】:

我想给我的字符串一个颜色,但是 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");
?>

结果如下:

【问题讨论】:

  • 有人帮我解决这个问题吗?
  • 没有与修改颜色工作方式相关的设置。您的示例应该可以正常工作。您使用的是什么版本的 dompdf? PHP版本?您是否收到任何 PHP 警告、通知或错误(如果没有,请尝试 ini_set('display_errors',true);)?

标签: php colors dompdf


【解决方案1】:

刚刚在这里尝试了您的代码: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

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

【讨论】:

  • 在哪里可以找到我的配置设置?
  • 再次检查我的答案
  • 我得到了同样的结果。检查这个:acros.netlogiq.info/pdf_generated/file.pdf。我可以在 setup.php 中更改什么?
  • 您是否尝试过我的代码?我的意思是没有重定向,只需在 die()exit() 的帮助下将 PDF 呈现在同一个文件中
  • 是的。我复制粘贴你的代码,我得到相同的结果
【解决方案2】:

看看这是一个例子:

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。

【讨论】:

  • 可以发给我截图吗?,另存为.html
  • 请再次查看我的帖子!查看我的完整代码和结果
  • 我收到此错误:致命错误:调用未定义的方法 DOMPDF::open_object()
猜你喜欢
  • 2010-11-13
  • 2021-07-18
  • 1970-01-01
  • 2019-03-11
  • 1970-01-01
  • 1970-01-01
  • 2012-03-07
  • 1970-01-01
相关资源
最近更新 更多