FPDF多单元文本包装

时间:2017-09-03 06:35:55

标签: php fpdf

你好,先生,你可以帮助我解决我的问题。我需要我的论文。我想要使​​用多单元格将文本包装在我的单元格中。我尝试观看视频并在这里寻找相同的问题,但我无法修复。请帮我理解如何做到这一点。如果你给我举例或者有更好的pdf生成器,那将是非常有用的。

这是我的代码

<?php
require('fpdf181/fpdf.php');
$conn = mysqli_connect("localhost", "root", "", "srdatabase");  

class PDF extends FPDF
{
    function Header()
    {
        $this->SetFont('Arial','B',12);
        $this->Cell(100, 10, 'Reports', 0,1);
        $this->Ln(5);
        $this->SetFont('Arial','B',7);
        $this->SetFillColor(180, 180, 255);
        $this->SetDrawColor(50,50,100);
        $this->Cell(26,10,'Full Name',1,0,'',true);
        $this->Cell(25,10,'Specialization',1,0,'',true);
        $this->Cell(190,10,'Description',1,0,'',true);
        $this->Cell(22,10,'Reserved Count',1,0,'',true);
        $this->Cell(18,10,'Date Added',1,1,'',true);
    }
}

$pdf = new PDF('P','mm', 'A4');
$pdf->AliasNbPages('{pages}');
$pdf->SetAutoPageBreak(true,15);
$pdf->AddPage('L','A4',0);
$pdf->setFont('Arial','',7);
$pdf->setDrawColor(50,50,100);

if(empty($_POST["from_date"]) && empty($_POST["to_date"])&& isset($_POST["search_text"])) 
{
    $search = mysqli_real_escape_string($conn, $_POST["search_text"]);

    $query = mysqli_query($conn, "
    SELECT * FROM speakers 
    WHERE speaker_fullname LIKE '%".$search."%'
    OR speaker_image LIKE '%".$search."%' 
    OR speaker_specialization LIKE '%".$search."%' 
    OR speaker_description LIKE '%".$search."%' 
    OR speaker_paymentcost LIKE '%".$search."%'
    OR speaker_reservedcount LIKE '%".$search."%' 
    OR date_added LIKE '%".$search."%' 
    ORDER BY date_added DESC"); 

    while($data=mysqli_fetch_array($query))
    {
        $pdf->Cell(26,10,$data['speaker_fullname'],1,0);
        $pdf->Cell(25,10,$data['speaker_specialization'],1,0);
        $pdf->Cell(190,10,$data['speaker_description'],1,0);
        $pdf->Cell(22,10,$data['speaker_reservedcount'],1,0);
        $pdf->Cell(18,10,$data['date_added'],1,1);
    }
}

这就是它的样子 enter image description here

1 个答案:

答案 0 :(得分:1)

看起来你可能希望$data['speaker_description']在太长的时候换行。无论如何,如果不是那个,你可以对所有列进行此操作。

您可以使用FPDF GetStringWidth()来查看它是否大于您提议的宽度,并且他们在每列上使用MultiCell()而不是Cell()。此外,请注意,如果您没有指定$pdf->SetAutoPageBreak( false);,则需要这样做(当您到达底部时添加页面)并确保在添加之前,最后一个单元格不会溢出到下面的页面中新页面。