PDF列未将宽度换行到新行

时间:2016-02-21 03:19:05

标签: php mysql pdf fpdf word-wrap

我已成功输出pdf,并且电子邮件和地址列的宽度与下一列重叠。我需要帮助,如何使它在新行中打印数据库中的结果,即使字长超过列宽,它应该只是打破并扩展整行的高度。 以下是我的代码;

     <?php
  require('fpdf.php');

 $db = new PDO('mysql:host=localhost;dbname=ddname;charset=utf8', 'root', '');
  $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

  $colNames = array();


   $result = $db->query("SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA='dbname' AND TABLE_NAME='table_name'");

  foreach($result as $row) {
  $colNames[]  = $row["COLUMN_NAME"];
 }

     $pdf = new FPDF('L','mm','A4');
     $pdf->AddPage();
     $pdf->SetDisplayMode(real,'default');

     $pdf->SetFont('Arial','B',12);      
     $pdf->SetTextColor(50,60,100);

     $pdf->SetDrawColor(50,60,100);
     $pdf->Cell(100,10,'Tabledata table_name',1,0,'C',0);

     $pdf->Ln();


      foreach($colNames as $colName) {
      $pdf->SetFont('Arial','B',8); 
      if($colName=="id")
   {
    $pdf->Cell(6,10,$colName,1);    
    } elseif($colName=="email_address"){     
     $pdf->Cell(22,10,$colName,1);}elseif($colName=="title"){    
    $pdf->Cell(10,10,$colName,1);}else
    {
    $pdf->Cell(22,10,$colName,1);   
    }
 }


 foreach($db->query("SELECT * FROM table_name") as $row2) {
  $pdf->Ln();
  foreach($colNames as $colName) {
  $pdf->SetFont('Arial','',8); 
    if($colName=="id")
   {
   $pdf->Cell(6,10,$row2[$colName],1);  
  } elseif($colName=="title"){    
  $pdf->Cell(10,10,$row2[$colName],1);}else
  {
  $pdf->Cell(22,10,$row2[$colName],1);  
  }
     } 
 }
   $pdf->Output();
   ?>

这是当前结果的示例   enter image description here

0 个答案:

没有答案