TCPDF and issues using added CSS

15,530

Solution 1

I've used TCPDF and colspan works perfectly, but i think that (unfortunately) you always have to use inline styles when converting HTML to TCPDF otherwise results might be unpredictable.

I know it's boring and lends to a lot of repetition, but that way colspan and style work perfectly for me.

Solution 2

CSS in TCPDF is mostly non-existent. To get any kind of useable CSS you might want to switch to dompdf https://github.com/dompdf/dompdf which can read external stylesheets, inline style tags etc

Share:
15,530
Del
Author by

Del

Updated on June 15, 2022

Comments

  • Del
    Del almost 2 years

    I'm trying to use TCPDF with my own classes to publish some content that is already existing in HTML and I can't get the CSS to play ball (not completely anyway).

    I know it's a pDF library and doesn't handle all CSS, but all I'm doing is some (very) basic formatting.

    I'm probably doing something really stupid, but for the life of me I can't see it.

    Anyway, I'm creating a variable with the style attributes in it like this:

    $html = <<<EOF
        <style>
        table.phonelist {
        border:1px solid black;
        }
        td {
        border:1px solid black;
        }
        td.header1 {
        background-color: #cccccc;
        border-bottom:1px solid black;
        font-weight: bold;
        text-align: center;
        font-size: 12pt;
        }
        td.header2 {
        font-weight:bold;
        text-align:center;
        font-size:12pt;
        }
        td.lname {
        font-weight:bold;
        }
        td.ext {
        text-align:center;
        }
        </style>
        EOF;
    

    Then I add some html onto the end of that string and write it out to the page, the HTML renders fine and SOME of the styles, for instance the header1 style is the larger font size and centered, but the background-color doesn't seem to do antything.

    Anyone can be of any help it would be great, if it is just pointing out my stupidity then would still work :-)

    Cheers.