PHP Dompdf Format HTML


PHP Dompdf Format HTML

我是使用dompdf的新手,我无法使用css文件或内联css来更改我创建的pdf的格式。我想更改表格的字体大小、颜色和单元格颜色。我不知道如何使用Dompdf来完成这项工作。谢谢你的帮助!我有一些例子说明我是如何在代码中尝试做到这一点的。

HTML/PHP代码:

$week_ending_date = date("m-d-Y", strtotime('this friday'));
$table = "table";
$tableBackground = "background: red";
$four = "2";
$pdf = "<html>
<head><title>Weekly Report</title></head>
<body>
<basefont size=".$four.">
<center><h4>Citations</h4>";
$pdf .= "<h4>".$pdfTimeFrame."</h4>";
$pdf .= "<h4>All Items from ".$Start." to ".$End."</h4></center>";
$pdf .= "<div id=".$table.">
         <table style=".$tableBackground.">
            <thead>
                <tr>
                    <th>Week Ending</th>
                    <th>W Number</th>
                    <th>Project Title</th>
                    <th>Project Contact</th>
                    <th>N Number</th>
                    <th>Verified By</th>
                    <th>Date Verified</th>
                    <th>Comments</th>
                    <th>Notes</th>
                    <th>Received</th>
                </tr>
            </thead>
            <tbody>";
while($row = oci_fetch_array($runQuery, OCI_ASSOC+OCI_RETURN_NULLS))
{
    $WNumber = $row['P_NUMBER']."-".$row['A_NUMBER'];
    $querySQLDB = "SELECT [Verified_By], [Comments], [Notes], [Date_Verified], [Week_Ending], [Date_Received] 
           FROM dbo.Information 
           WHERE dbo.Information.Key_ID = '$WNumber' 
           ORDER BY dbo.Information.ID DESC";
    $dbe->query($querySQLDB);
    $sqlData = $dbe->fetch();
    $WeekEndingLessTime = str_replace("12:00:00:000AM"," ",$sqlData['Week_Ending']);
    $dateNoTime = str_replace("12:00:00:000AM"," ",$sqlData['Date_Verified']);
    $dateReceived = str_replace(":00:000"," ",$sqlData['Date_Received']);
    $pdf .= "<tr>
                <td>
                ".$week_ending_date."
                </td>
                <td>
                ".$WNumber."
                </td>
                <td>
                ".$row['TITLE']."
                </td>
                <td>
                ".$row['PROJECT_MANAGER_N']."
                </td>
                <td>
                ".$row['PROJECT_MANAGER_O']."
                </td>
                <td>
                ".$sqlData['Verified_By']."
                </td>
                <td>
                ".$dateNoTime."
                </td>
                <td>
                ".$sqlData['Comments']."
                </td>
                <td>
                ".$sqlData['Notes']."
                </td>
                <td>
                ".$dateReceived."
                </td>
             </tr>
            ";
}
$pdf .= "   </tbody>
         </table>
         </div>";
$pdf .= "</body></html>";
$dompdf = new DOMPDF(); 
$dompdf->load_html($pdf);
$dompdf->render();
$dompdf->stream("Report_'".$week_ending_date."'.pdf", $pdf);
$pdf = "<html>
<head>
  <style>
  body{
      color: blue;
  }
  </style>
  <title>Weekly Report</title>
</head>

基本上,我试图在错误的地方格式化。不过它现在正在工作。