how to use PHP to write the PDF?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • apssiva
    New Member
    • Feb 2011
    • 26

    how to use PHP to write the PDF?

    Hi

    If I use the regular PHP:

    Code:
    while($row = mysql_fetch_array($result))
    {
    $html = '<table><tr><td>';
    echo $row['title'];
    $html .= '</td></tr></table>';
    
    $mpdf->WriteHTML($html);
    $mpdf->AddPage();
    }
    $mpdf->Output('SGC.pdf','D');
    It freaks out at me and the PDF won't write at all.

    Code:
    for($i=0;$i<$count;$i++)
    {
    print_r ($unser[$i][0]);
    }
    how to write $unser value in pdf?
  • johny10151981
    Top Contributor
    • Jan 2010
    • 1059

    #2
    How many tables and how many rows you intend to add

    Make sure the directory has write permission.

    Your echo is echoing directly to browser. on the other mpdf will send data to Browser so a conflict with header will occur.
    how?
    Your echo is sending data to browser

    then your page is creating header to force browser to download pdf file. as a result an error will be generated.

    You are not putting any visible data to the pdf at all

    mend your logic. lots of bug there.

    Comment

    • johny10151981
      Top Contributor
      • Jan 2010
      • 1059

      #3
      A Simple Example
      pdf.php
      Code:
      <?php
      include("../mpdf.php");
      $mpdf=new mPDF();
      $mpdf->WriteHTML('<p>Hallo World</p>');
      $html="<table>";
      $html.="<tr>";
      for($i=1;$i<10;$i++)
      {
      $html.="<td>".$i."</td>";
      }
      $html.="</tr>";
      $html.="</table>";
      $mpdf->WriteHTML($html);
      $mpdf->Output('filename.pdf');

      Comment

      • apssiva
        New Member
        • Feb 2011
        • 26

        #4
        Hi,

        Thank you for your help. I tried my self, its display in pdf successfully. But it doesn't display ite1 value in the pdf. Could you please, correct my mistake?

        Code:
        <?php
        set_include_path($_SERVER['DOCUMENT_ROOT'] .'/mpdf/'); 
        
        require('mpdf.php');
        
        $n = 0;
        $mpdf=new mPDF();
        
        	require_once('../../includes/common.php');
         	$result = mysql_query("SELECT * from sgc where year = '2010'") or die(mysql_error());
        	$row=mysql_fetch_array($result);
        	$nric=$row['nric'];
        	$row=mysql_fetch_array($result);
        	$meta_ite=$row['meta_ite'];
        
        $mpdf->WriteHTML('<p>Hallo World</p>');
        
        $html1 = '<table>
          			<tr>
            		<td width="388">Module Description</td>
            		<td width="111"><div align="center">Grade</div></td>
            		<td width="92"><div align="center">Earned</div></td>
            		<td width="96"><div align="center">Authority</div></td>
            		<td width="74"><div align="center">Series</div></td>
          			</tr>';
          		  $unser = $meta_ite;
        		  $unser = unserialize($unser);
        		  $count = count($unser);
        		 [b] for($j=0;$j<$count;$j++)
        		  {
        			  $ite1 = "print_r ($unser[$i][0])";
        					//print_r ($unser[$i][0]."--".$unser[$i][1]."--".$unser[$i][2]);
        
          $html1 .= '<tr><td width="388">'.$nric.'</td>
            <td width="111">'.$count.'</td>
            <td width="92"><div align="center">'.$ite1.'</div></td>
            <td width="96">ITE</td>
            <td width="74">2010</td>
          	</tr>';
        		  }[/b]
          $html1 .= '</table>';
          
        $mpdf->WriteHTML($html1);
        $mpdf->Output('filename.pdf','D');
        ?>

        Comment

        Working...