使用mpdf时无法识别样式

问题描述

这是我的代码

    $htmls ='<html><body style="font-size:100px;">
    <table style="width:100%;border-spacing: 0px; margin-top: 10px;background-color: #FF5733;font-size:100px;" >
                      <tr>
                         <td  style="padding: 5px 8px; font-weight: bold;">TEST</td>
                         <td style="padding: 5px 8px;"> Test1 </td>
                         <td style="padding: 5px 8px;"> Test2 </td>
                      </tr>
                  </table></body></html>';
    
       require './mpdf60/mpdf.PHP';
       $mpdf = new mPDF('utf-8','A4',1);
       $mpdf->SetdisplayMode('fullpage');
       $mpdf->autoLangToFont = true;
       $mpdf->autoScriptToLang = true;
       $mpdf->useSubstitutions = false;
       $mpdf->simpleTables = true;
       $mpdf->packTableData = true;
       $mpdf->showImageErrors = true;
       $mpdf->list_indent_first_level = 0;
       $mpdf->WriteHTML($html);
       $fname = date('Y-m-d-h-i-s') . ".pdf";
       $mpdf->Output(__DIR__ . "/pdf/" . $fname);
       $filePath =__DIR__ . "/pdf/" . $fname;

输出

enter image description here

我需要它。

enter image description here

如何修复它。创建css文件对我来说很困难,因为我在所有标签上使用了不同的样式。

解决方法

您正在使用旧版本的mPDF。它的当前稳定版本是您使用的版本之前的 2个主要版本

您的代码包含错字。将$htmls更改为$html

当我使用mPDF 8(.0.7)测试您的代码时,事情进展顺利,这是我得到的输出:

Output from my test of your fixed code with mPDF 8