How to align image in table td, tcpdf

13,696

Solution 1

Adding the following CSS to your td should work:

td {
    vertical-align: middle;
    text-align:center;
}

See a fiddle of it working.

Solution 2

Did you check image alignment?

<img align=center src="abc.jpg" width="20" height="20" >
Share:
13,696
Lucky Ali
Author by

Lucky Ali

Updated on June 18, 2022

Comments

  • Lucky Ali
    Lucky Ali almost 2 years

    I use tcpdf to generate pdf files.

    And there's a problem in aligning image in table td.

    I am uising $pdf->writeHTML($html, true, false, true, false, ''); in tcpdf.

    enter image description here

    html is clear from the image i have shared. html is just simple as

    <table>
      <tr>
        <td>&nbsp</td>
        <td>Picture</td>
        .......
      </tr>
      <tr>
        <td>1</td>
        <td style="text-align:center"><img src="abc.jpg" width="20" height="20" ></td>
        .......
      </tr>
    </table>
    

    Note: align="center", valign="middle" , css margin and padding ... nothing seems to work I tried on

    text-align:center push into center but not vertically.

  • Peter
    Peter almost 9 years
    Unfortunatly, work on HTML, but don't work when you throw the HTML to TCPDF. :(
  • Denis Chenu
    Denis Chenu over 8 years
    tcpdf, not css. tcpdf don't have margin in writeHtml
  • Denis Chenu
    Denis Chenu over 8 years
    text-align:center is OK. vertical-align: middle; : Not OK. Must try with setHtmlVSpace and a p/div/h5 or h6 inside the cell ....