php
  • pdf
  • html2pdf
  • 2017-05-31 87 views 3 likes 
    3

    我正在使用html2pdf生成pdf.i,需要动态生成一些行。 我的代码..使用html2pdf生成pdf中的动态行

      <?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'); 
    

    我如何添加这个content.If PHP内它不工作无论如何请建议别的东西来生成你

    +0

    你可以给你想要添加的示例动态行吗? –

    +0

    我需要从数据库中获取值。$ List = mysql_query(“somequery”); \t \t \t \t \t而($元素= mysql_fetch_array($列表)) \t \t \t \t \t \t \t \t { \t \t \t \t \t \t \t \t //添加行根据导致 \t \t \t \t \t \t \t \t} – Nola3191

    +0

    如何集成这个代码$内容 – Nola3191

    回答

    1

    你能不能做pdf..Thank这就像基本的PHP?

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

    添加变量ok..but我需要使用像$内容=” ..

    ​​如果(东西){回声‘东西’}
    OR while(condition){//这里生成行}
    Nola3191

    1

    试试这个:

    <?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

    其工作感谢你:) @Adhan Timothy Younes – Nola3191

    1

    你可以做到这一点,就像这样:

    $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>'; 
    

    您可以使用三元运算符的条件,而不是if/else语句:

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

    其工作谢谢:) @ Alex197 – Nola3191

    相关问题