7
votes

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.

3
did you check appling <td align="center"> - gayan
@gayan . this doesn't work - Lucky Ali
have you tried text-align: center; on the td? - naththedeveloper
How about adding vertical-align: middle; aswell as text-align:center; then? Does that work? - naththedeveloper
@fdl it worked thanks - Lucky Ali

3 Answers

3
votes

Adding the following CSS to your td should work:

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

See a fiddle of it working.

2
votes

Did you check image alignment?

<img align=center src="abc.jpg" width="20" height="20" >
-2
votes

you can use : CSS:

td img{
    margin:0 auto;
}

or use like @gayan