【问题标题】:Dompdf style isn't workingDompdf 样式不起作用
【发布时间】:2018-11-01 05:13:49
【问题描述】:

我正在尝试使用 dompdf,即使我的脚本生成了一个 pdf 文档,样式标签也不起作用,这是我的代码。我了解它是如何工作的,并且已经成功地将它与 html 一起使用,但这是我第一次使用 css 并且它不起作用。

    require_once 'dompdf/autoload.inc.php';
?>
<?php

$nom=$_GET['nom'];
$prenom=$_GET['prenom'];
$email=$_GET['email'];
$numeroCommande=$_GET['numerocommande'];
$commandeTotal=$_GET['commandeTotal'];?>
<?php ob_start();?>
<!DOCTYPE html>
<html>
<head>
<meta charset='utf-8'>

    <title>Title</title>
</head>
<body>
<div class='invoice-box'>
        <table cellpadding='0' cellspacing='0'>
            <tr class='top'>
                <td colspan='2'>
                    <table>
                        <tr>
                            <td class='title'>
                                <img src='https://www.hollandbikes.com/img/holland-bikes-logo-1493142780.jpg' style='width:100%; max-width:300px;'>
                            </td>

                            <td>
                                Facture N°: <?php echo $numeroCommande ?> <br>
                                Date: January 1, 2015<br>

                            </td>
                        </tr>
                    </table>
                </td>
            </tr>

            <tr class='information'>
                <td colspan='2'>
                    <table>
                        <tr>
                            <td>
                                Holland Bikes<br>
                                24 rue Firmin Gillot<br>
                                75015 Paris
                            </td>

                            <td>
                                <br>
                                <?php echo $prenom.' '.$nom ?><br>
                                <?php echo $email ?>
                            </td>
                        </tr>
                    </table>
                </td>
            </tr>

            <tr class='heading'>
                <td>
                    Méthode de paiement
                </td>

                <td>
                    Carte Bleue
                </td>
            </tr>


            <tr class='total'>
                <td></td>

                <td>
                   Total: <?php echo $commandeTotal ?>€
                </td>
            </tr>
        </table>
    </div>
</body>
</html>
<?php
$html = ob_get_clean();?>

<?php 

require_once 'dompdf/autoload.inc.php';
?>
<?php

// reference the Dompdf namespace

use Dompdf\Dompdf;

// instantiate and use the dompdf class
$dompdf = new Dompdf();
$dompdf->loadHtml($html);

 // (Optional) Setup the paper size and orientation
$dompdf->setPaper('A4', 'landscape');

// Render the HTML as PDF
$dompdf->render();

// Output the generated PDF to Browser
$dompdf->stream(); ?>

你知道为什么这个标签不起作用吗?它应该接受基本的css,这就是为什么我不明白问题出在哪里。

【问题讨论】:

  • 您使用的是哪个版本的 dompdf。可能与此重复。 stackoverflow.com/questions/18008637/…
  • 我阅读了这个帖子,但它没有回答我的问题。我用的是最新版的dompdf,真的被屏蔽了。
  • 显然,当我直接在html中添加css作为样式属性时,它可以工作,但是css的不工作真的很奇怪。你有解释吗?

标签: php css dompdf


【解决方案1】:

显然,不支持 line-height,我删除了它,它工作得很好。

【讨论】:

    猜你喜欢
    • 2014-02-13
    • 2011-06-27
    • 1970-01-01
    • 1970-01-01
    • 2014-11-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-12-22
    相关资源
    最近更新 更多