Jump to content

How do i add css in tcpdf?


sashavalentina

Recommended Posts

I wanted to do auto numbering for my tables with css using TCPDF. I tried both ways but it does not work at all.

I tried the one in the documentation of tcpdf and it does not work too. Can anyone give me a piece of advice on how to make this work? 

These are the both ways i mentioned and it did not work. 

    $htmlcontent .='
    <style>
    table {
		  counter-reset: rowNumber;
		}

		table tr::before {
		  display: table-cell;
		  counter-increment: rowNumber;
		  content: counter(rowNumber) ".";
		  padding-right: 0.3em;
		  text-align: right;
		}
    </style>
    <table id="receiptTable" cellpadding="3" style="max-height: 1000px;">
        <tr>
         <td width = "7%"style=" font-weight: normal;font-size: 12px;line-height: 17px;color: #000000;">
               
            </td>
        
            <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>

    ';
    }

for this i use the method of including external css into my tables but it does not work as well. I did make sure my file path is correct. (the code below)
 

 $htmlcontent .='
    <style>.file_get_contents(css/receipt.css).</style>
    <table id="receiptTable" cellpadding="3" style="max-height: 1000px;">
        <tr>
         <td width = "7%"style=" font-weight: normal;font-size: 12px;line-height: 17px;color: #000000;">
               
            </td>
        
            <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>

    ';
    }

 

Link to comment
Share on other sites

10 hours ago, sashavalentina said:

I wanted to do auto numbering for my tables with css using TCPDF. I tried both ways but it does not work at all.

What "both ways"?

 

10 hours ago, sashavalentina said:

I tried the one in the documentation of tcpdf and it does not work too.

Which one?

I'm sure it can work, so there's probably something different about your code. Did you check that the HTML works in a regular webpage? What's the rest of the code?

Link to comment
Share on other sites

It would appear that some CSS is implemented (such as font-size, line-spacing, color and other basics) but others are not. Your counter appears to be in those that are not. Those that do work can be in a <style> section or in-line.

There may be a list in the documentation, who knows? If there were a prize for the worst documentation, tcpdf would win it outright. I have to resort to examining the source code to find out what arguments each method requires and what it does.

For the counter you may have to resort to the age-old method of outputting an incremented counter variable.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.