如何使 css 在 tcpdf 中工作?

问题描述

我想在我的tcpdf中实现使用css自动给我的表格行编号的功能。我不知道为什么它不起作用。我确实在常规网站上查看过它,它运行良好。但我不知道为什么当我将它添加到我的 tcpdf 时它根本不起作用。有谁知道这个问题的解决方案?请帮我。任何建议将被认真考虑。提前致谢。

 $htmlcontent .= '<style>
    table {
        counter-reset: rowNumber;
      }
      
      table tr.receiptcontent::before {
        display: table-cell;
        counter-increment: rowNumber;
        content: counter(rowNumber) ".";
      
      }
       </style>';

    $htmlcontent .='
    <table cellpadding="11" style="max-height: 1000px;">
        <tr class="receiptcontent">

            <td colspan="3" style="font-weight: normal;font-size: 12px;line-height: 17px;color: #000000;">
                '.$irow['product_title'].'
            </td>
            
             <td style=" font-weight: normal;font-size: 12px;line-height: 17px;color: #000000;">
               '.$irow['product_sku'].'
            </td>
             <td style=" font-weight: normal;font-size: 12px;line-height: 17px;color: #000000;">
               '.$irow['quantity'].' '.$irow['quantity_unit'].'
            </td>
             <td style=" font-weight: normal;font-size: 12px;line-height: 17px;color: #000000;">
              RM '.$irow['product_buy_price'].'
            </td>
            <td  width= "20%" style=" font-weight: normal;font-size: 12px;line-height: 17px;color: #000000;">
                RM '.$irow['purchase_price'].'
            </td>
        </tr>
    </table>

    ';
    }

解决方法

在将 HTML 发送到 TCPDF 时内联 CSS

将您的 css 添加到单独的 css 文件中并将其包含在 html 中:

eg: $htmlcontent .='<style>'.file_get_contents('./style.css').'</style>';