【问题标题】:Dompdf 1.0 - CSS border property not working?Dompdf 1.0 - CSS 边框属性不起作用?
【发布时间】:2025-12-29 06:30:06
【问题描述】:

我正在使用 dompdf 1.0 版本将我的 html 呈现为 pdf 。 css 边框属性对我不起作用。 下面是我的pdf代码。 (示例pdf.php)

<?php

$html = "<!DOCTYPE html>
<html>
<head>
<style>
table, th, td {
  border: 1px solid black;
  color : blue;
}

</style>
</head>
<body>

<h2>Table With Border</h2>

<p>Use the CSS border property to add a border to the table.</p>

<table style='width:100%'>
  <tr>
    <th>Firstname</th>
    <th>Lastname</th> 
    <th>Age</th>
  </tr>
  <tr>
    <td>Jill</td>
    <td>Smith</td>
    <td>50</td>
  </tr>
  <tr>
    <td>Eve</td>
    <td>Jackson</td>
    <td>94</td>
  </tr>
  <tr>
    <td>John</td>
    <td>Doe</td>
    <td>80</td>
  </tr>
</table>

</body>
</html>";
$filename = "newpdffile";

// include autoloader
require_once 'dompdf/autoload.inc.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($filename,array("Attachment"=>0));

以下是我的 pdf 的输出。

以下是我在浏览器中的 html 代码输出。

问题是 css 中的边框属性在我的 pdf 中不起作用。有什么帮助吗?我的php版本是7.3.11。

【问题讨论】:

    标签: php css border dompdf


    【解决方案1】:

    看起来这是这个版本的错误。 我有完全相同的问题,所以我已经在github上创建了问题https://github.com/dompdf/dompdf/issues/2331

    【讨论】:

    • 这个问题随着 dompdf 1.0.1 的发布而得到修复
    【解决方案2】:

    新版本的 dompdf 好像有问题 你应该改变你的边界值 边框:1px纯黑色; 至 边框:纯色 1px 黑色; 对我来说它有效! 参考链接 https://github.com/dompdf/dompdf/issues/2331#issuecomment-751560493

    【讨论】: