Generate dynamic strings in pdf using html2pdf

I am using html2pdf to generate pdf.i to generate some lines dynamically. My code ...

         <?php
        require_once("html2pdf.class.php");
        $content = '<html><body><table border="0"  >
        <tr><td align="center" > <h4><b> CHAMPIONSHIP
        2015-16</b> </h4></td> </tr>
        <tr><td align="center"><h4><b>
        </b></h4></td></tr>
        <tr><td align="center"><h4><b>DETAILED ENTRY</b>
        </h4> </td></tr>
        <tr><td><h4><b>Name of Manager :</tr>

        </table>
        $html2pdf = new HTML2PDF
        ('L','A4','de',true,'UTF-8',array(10, 10, 10, 10));
        $html2pdf->WriteHTML($content);
        $html2pdf->Output($filename.'.pdf');

      

How can I add php inside this content. If it doesn't work, PLUS will suggest something else to generate the pdf. Thank.

+3


source to share


3 answers


Can't you do it like basic PHP?



$your_var = 'what you want';

$content = '<html><body><table border="0">';
$content .= '<html code...>'.$your_var.'</...html code>';
$content .= '</table></body><html>';

      

+1


source


Try the following:



 <?php
    require_once("html2pdf.class.php");
    $content = '<html><body><table border="0"  >';
    db.$List = mysql_query("somequery"); 
    while($element= mysql_fetch_array($List)) { 
    $content .= '<tr><td>'.$element["value"].'</td></tr>';
    }

    $content .= '</table></body></html>';
    $html2pdf = new HTML2PDF
    ('L','A4','de',true,'UTF-8',array(10, 10, 10, 10));
    $html2pdf->WriteHTML($content);
    $html2pdf->Output($filename.'.pdf');

      

+1


source


You can do it like this:

$content = '<html><body><table border="0">';
$content .= '<tr><td>';
if(your_condition){
    $content .= 'what you want';
}
$content .= '</td></tr>';
while(other_condition){
    // What you want in your loop (generate rows)
    $content .= '<tr><td>'.$line_number.'</td></tr>';
}
$content .= '</table></body><html>';

      

You can use ternary operator for conditions instead of if / else:

$content .= '<tr><td>'.(condition ? 'Some text' : 'other text').'</td></tr>';

      

+1


source







All Articles