Dompdf 1.0 - CSS 边框属性不起作用?

问题描述

我正在使用 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的输出

enter image description here

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

enter image description here

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

解决方法

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