Reputation: 495
I want to generate dynvouchers pdf with tcpdf. I can get right pdf without username and password. This is my code :
$html = '';
$html .= '<table><tr>';
for ($a = 1; $a <= 5; $a++) {
$html .= '
<td>
<div style="height: 300px; width: 320px;background-image:url(Voucher5.png)">
<br><br><br><br><br><br>
<table style="height: 20px; margin: 0px 0px 0px 10px;" width="300">
<tr>
<td width="160">'.$username.'</td>
<td width="160">'.$password.'</td>
</tr>
</table>
</div>
</td>';
if($a%2==0){
$html.='</tr><tr><td></td></tr><tr>';
}
$pdf->writeHTML($html, true, false, true, false, '');
$pdf->lastPage();
$pdf_file_name = 'custom_header_footer.pdf';
$pdf->Output($pdf_file_name, 'I');
I want pdf pages like this .
Upvotes: 0
Views: 2604
Reputation: 527
TCPDF limited support for css attributes. background-image
Not supported by TCPDF. You can use background-color
property instead of background-image
.
Refer: TCPDF - adding a background to a table cell or div that shows on PDF
$html = '';
$html .= '<table cellspacing="3" cellpadding="3"><tr>';
for ($a = 1; $a <= 5; $a++) {
$html .= '
<td>
<div style="background-color:blue; color:#fff; text-align: center;">
<br><br><br><br>
<table border="1" >
<tr>
<td width="100">'.$username.'</td>
<td width="100">'.$password.'</td>
</tr>
</table>
</div>
</td>';
if($a%2==0){
$html.= '</tr><tr>';
}
}
$pdf->writeHTML( $html, true, false, true, false, '');
$pdf->lastPage();
$pdf_file_name = 'custom_header_footer.pdf';
$pdf->Output($pdf_file_name, 'I');
Upvotes: 1
Reputation: 1620
I don't know where your username/password values are coming from, this could be from a database query or file, etc. So you need to include that in your code to set the username/password data.
However, the way you are concatenating strings and PHP variables is incorrect.
Instead of using <td width="160">'$username'</td>
you should use DOT characters to correctly concatenate your php-variables in the HTML(that is a string) using this manner:
<td width="160">' . $username . '</td>
Hope that helps you on your way.
Upvotes: 0