-1

hello kind sir's may you help me with my problem. Please i need for my thesis. what i is want to wrap the text in my cell using multi cell. I try to watch videos and look for the same question here but i cant fix. Please help me understand how to do it. It would be very helpul if you give me examples or is there a better pdf generator.

this is my code

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

this is what it looks like enter image description here

Red
  • 133
  • 2
  • 14

1 Answers1

1

It looks like you probably want the $data['speaker_description'] to wrap when it is too long. At any rate, if that isn't the one, you can do this to all of columns.

You can use FPDFs GetStringWidth() to see if it would be greater than the width you have proposed and them make use MultiCell() on each column rather than Cell(). Also, please note that if you are not specifying $pdf->SetAutoPageBreak( false);, you will need to do that ( adding pages when you reach the bottom ) and make sure the last cell of the wouldn't overflow into the page below before adding a new page.

Tyler Christian
  • 520
  • 7
  • 14
  • i tried to make it multicell but it mess up the row below it. So if you give me an example it would be really helpful – Red Sep 06 '17 at 22:14
  • https://stackoverflow.com/questions/13559330/fpdf-print-multicell-adjacently you will basically replace all of your cell calls with MultiCell – Tyler Christian Sep 07 '17 at 02:09