tags:

views:

693

answers:

3

Trying to create proper PDF document, using PHP and TCPDF.

Can you help me, how can I use writeHTML function to create and center table, in TCPDF?

Tryed with:

 $html = '

 <div style="margin-left: auto; margin-right: auto; width: 50%">
  <table border="1" width="200" align="center"><tr><td><b>Invoice number: '.$this->xInvoiceNumber.'</b></td></tr></table>
  <br />
  <table border="1" width="200" align="center"><tr><td>'.$this->xClient.'</td></tr></table>
  <br />
 </div>

... but no luck.

A: 

Try replacing your opening div tag with this...

<div style="margin:5px auto; width:50%">
Zeratore
A: 

Never done anything like this however, this is the code you would need to center a table that is the cross browser compatible

<div style="text:align:center;">
  <table style="margin:0px auto" border="1" width="200" align="center">
    <tr>
      <td><b>Invoice number: </b></td>
    </tr>
  </table>
  <br />
  <table style="margin:0px auto"border="1" width="200" align="center">
    <tr>
      <td>Client</td>
    </tr>
  </table>
  <br />
</div>

If pdfs support css i would advise styling the html elements using css

table{
  border:1px solid black;
  margin:0px auto;
  text-align:center;
  width:200px;
}

Hope this helps!

cr1ms0n3cho
well... with next code: <div style="text-align:center;"> <table border="1" width="200" align="center"> <tr> <td> <b>Invoice number: 123</b> <br /> Invoice date: 2010-04-09 </td> </tr> </table> <br /> </div>... text is centered, but borders of the table is aligned to left.also, it would be nice if text can be aligned left in table... but i don't know is it possible...
yes i am also trying to find the answer to that prob!
ina
+1  A: 

Ok, so I don't know if there is solution for my problem...

However, I did manage to solve it by using writeHTMLCell funcion, ie.

$this->writeHTMLCell(50, 0, 50, 50, 'cellcontent', 'LRTB', 1, 0, true, 'L'); 

If somebody can find better solution, please reply.

Tnx!