Skip to content

writeHTML(): type selectors in <style> blocks are ignored, only class selectors apply (7.x regression) #876

Description

@naumso

Environment: tecnickcom/tcpdf 7.0.6, tc-lib-pdf 8.70.3, PHP 8.5

In TCPDF 7, CSS rules with element/type selectors (body { … }, table { … },
td { … }) inside a <style> block are silently ignored by writeHTML().
Class selectors from the same block are applied fine. TCPDF 6 applied type
selectors, so documents relying on e.g. body { text-align: center } +
table { width: 205mm } lose their entire layout after upgrading, while
class-based rules (.title { font-weight: bold }) keep working — which makes
the regression easy to miss partially.

Reproduce:

$pdf = new TCPDF('P');
$pdf->setPrintHeader(false);
$pdf->setPrintFooter(false);
$pdf->setMargins(0, 0, 0, true);
$pdf->setAutoPageBreak(false, 0);
$pdf->setFont('freesans', '', 14);
$pdf->AddPage();

$html = '<!DOCTYPE html><html><head><style>
    body  { text-align: center; }   /* ignored in 7.x */
    table { width: 205mm; }         /* ignored in 7.x */
    .big  { font-size: 1.5em; }     /* applied */
</style></head><body>
<table><tr><td class="big">This should be centered in a 205mm-wide table</td></tr></table>
</body></html>';

$pdf->writeHTML($html, true);
$pdf->Output('repro.pdf', 'I');

Expected (TCPDF 6): table is 205mm wide, text centered, .big applied.
Actual (7.0.6): table shrinks to content, text left-aligned; only .big
is applied.

If dropping type-selector support is intentional for the new engine, it would
be worth listing under "Breaking Changes" in the README — currently the docs
state the HTML output is structurally equivalent to legacy.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions