【发布时间】: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。
【问题讨论】: