FPDF PHP MYSQL文本不适合单元格

我想从MySql数据库中导出pdf格式的数据。我可以在mysql数据库中执行此操作,这非常好。我试着让它自动化。我使用了FPDF库,但是数据不适合表格。我找过了,但没能修好。

我该怎么做?

图片:

我的专栏:

?

?

示例内容:

?

我的代码:

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

//Database 
require_once __DIR__ . '/db_config.php';
$connection = 
mysqli_connect(DB_SERVER,DB_USER,DB_PASSWORD,DB_DATABASE);

if(!$connection){
    die("Connection error  : " . mysqli_connect_eror());
}

class PDF extends FPDF
 {
    // Page header
    function Header()
    {
        $ImagePath ='image url';
        // Logo
        $this->Image($ImagePath,10,70,0,90);
        $this->SetFont('Arial','B',13);
        // Move to the right
        $this->Cell(80);
        // Title
        $this->Cell(80,10,'title',1,0,'C');
        // Line break
        $this->Ln(20);
    }
     
    // Page footer
    function Footer()
    {
        // Position at 1.5 cm from bottom
        $this->SetY(-15);
        // Arial italic 8
        $this->SetFont('Arial','I',8);
        // Page number
        $this->Cell(0,10,'Page '.$this- 
    >PageNo().'/{nb}',0,0,'C');
    }
    
 }
 // Columns 
    $display_heading = array('JobId'=>'JobId','ReleaseDate'=> 
'ReleaseDate', 
'StartingDate'=> 
'StartingDate','TargetTime'=>'TargetTime','JobContent'=> 

     'JobContent','KindId'=>'KindId','JobStatus'=>'JobStatus','CustomerId'  
=>'CustomerId');
    
 // Database Result    
    $result = mysqli_query($connection, "SELECT * FROM Jobs;") or die("database 
 error:". mysqli_error($connection));
    $header = mysqli_query($connection, "SHOW columns FROM Jobs");
    
    // Settings
    $pdf = new PDF();
    //header
    $pdf->AddPage();
    //foter page
    $pdf->AliasNbPages();
    $pdf->SetFont('Arial','B',8);
    foreach($header as $heading) {
    $pdf->Cell(24,7,$display_heading[$heading['Field']],1);
    }
    foreach($result as $row) {
    $pdf->Ln();
    foreach($row as $column)
    $pdf->Cell(24,7,$column,1);
    
    }
    $pdf->Output();

 //Connection close
 mysqli_close($connection);

 ?>

转载请注明出处:http://www.aqguliang.com/article/20230330/1771932.html