2
votes

I am using TCPDF library to generate a PDF. In that I have HEADER image and a table in content area as shown below screenshot:

enter image description here

As you are able to see that table is at left of the PDF, i want it to be at center. I tried to change the value configuration file(tcpdf_config_alt.php) file by changing value of define ('PDF_MARGIN_LEFT', 5); but what is happening is the header image is also moving to right as in following screenshot. enter image description here

but what i want is in following screen shot: enter image description here Then I tried to move the table in my html code but still the table doesn't come to center of PDF. The margin-left i given to table is not appied.

HTML code in TCPDF php file:

$tbl =  '<html>';
$tbl .= '<body>';
$tbl .= '<table style="margin-top:10px; margin-left:300px;" width="50%" border="1" align="left" cellpadding="5" cellspacing="0">';
$tbl .= '<tr>';
$tbl .= '<td><b>Agent Name</b></td>';
$tbl .= '<td><b>'.$agent_name.'</b></td>';
$tbl .= '</tr>';
$tbl .= '<tr>';
$tbl .= '<td><b>Port</b></td>';
$tbl .= '<td>'.$port.'</td>';
$tbl .= '</tr>';
$tbl .= '<tr>';
$tbl .= '<td><b>Address</b></td>';
$tbl .= '<td>'.$address.'</td>';
$tbl .= '</tr>';
$tbl .= '<tr>';
$tbl .= '<td><b>Telephone</b></td>';
$tbl .= '<td>'.$tel.'</td>';
$tbl .= '</tr>';
$tbl .= '<tr>';
$tbl .= '<td><b>Fax</b></td>';
$tbl .= '<td>'.$fax.'</td>';
$tbl .= '</tr>';
$tbl .= '<tr>';
$tbl .= '<td><b>Contact</b></td>';
$tbl .= '<td>'.$contact.'</td>';
$tbl .= '</tr>';
$tbl .= '<tr>';
$tbl .= '<td><b>Email ID</b></td>';
$tbl .= '<td>'.$email_id.'</td>';
$tbl .= '</tr>';
$tbl .= '<tr>';
$tbl .= '<td><b>Website Address</b></td>';
$tbl .= '<td>'.$website_address.'</td>';
$tbl .= '</tr>';
$tbl .= '</table>';
$tbl .= '</body>';
$tbl .= '</html>';

so please can anyone help me to resolve this issue. Thanks in advance.

1

1 Answers

0
votes

I have a tricky way. You can add in the beginig of each row

<th bgcolor="#fff" width="300px" style="border:none;"></th>

So the width of this invisible th will work as margin for the table.