?
Solved

FPDF MultiCell wrapping issue

Posted on 2011-02-13
1
Medium Priority
?
2,891 Views
Last Modified: 2012-05-11
I have created a PDF report using FPDF which worked great, until I had to wrap text in the cells. I read an article saying replace cell with MultiCell which compiles, but each cell now goes underneath each other instead of next to each other.

Ive had a look at www.fpdf.org and cant seem to find out what Ive done wrong, Ive done some searches and again cant find anything wrong.

If anyones had any experience with this, PLEASE HELP :-S

Thank you
<?php
require('../../Scripts/fpdf16/fpdf.php');
class PDF extends FPDF
{

function Header()
{
    //$this->Image('myPic.jpg',10,8,33);
    $this->SetFont('Arial','B',15);
    $this->Cell(80);
    $this->Cell(30,10,'Title - BETA',1,0,'C');
    $this->Ln(20);
}
function Footer()
{
    $this->SetY(-15);
    $this->SetFont('Arial','I',8);
    $this->Cell(0,10,'Page '.$this->PageNo().'/{nb}',0,0,'C');
}

//Load data
function LoadTestData()
{
    for ( $counter = 0; $counter <= 100; $counter ++) {
        $data[]=array('Col1Value', 'Col2', 'Col3', 120);
    }   

    return $data;
}


function FancyTable($header,$data)
{
    //Colors, line width and bold font
    $this->SetFillColor(255,0,0);
    $this->SetTextColor(255);
    $this->SetDrawColor(128,0,0);
    $this->SetLineWidth(.3);
    $this->SetFont('','B');

    //Header
    $w=array(40,35,40,45);
    for($i=0;$i<count($header);$i++)
        $this->Cell($w[$i],7,$header[$i],1,0,'C',true);
    $this->Ln();
    //Color and font restoration
    $this->SetFillColor(224,235,255);
    $this->SetTextColor(0);
    $this->SetFont('');

    //Data
    $fill=false;
    foreach($data as $row)
    {
        $this->MultiCell($w[0],6,$row[0],0 ,'L',$fill);

        $this->MultiCell($w[1],6,$row[1],0 ,'L',$fill);

        $this->MultiCell($w[2],6,$row[2],0 ,'L',$fill);

        $this->MultiCell($w[3],6,$row[3],0 ,'L',$fill);

        $this->Ln();
        $fill=!$fill;
    }
    $this->Cell(array_sum($w),0,'','T');
}
}

$pdf=new PDF();
//Column titles
$header=array('Country','Capital','Area (sq km)','Pop.');

//Data loading
$data=$pdf->LoadTestData();

$pdf->SetFont('Arial','',14);
$pdf->AddPage();
$pdf->FancyTable($header,$data);
$pdf->Output();
?>

Open in new window

0
Comment
Question by:tonelm54
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 27

Accepted Solution

by:
Lukasz Chmielewski earned 2000 total points
ID: 34885884
Try this way,
http://www.fpdf.de/downloads/addons/3/
This is the example of cells which additionally have wrapping, and you don't have to pull your hair out with the somehow - not - so fine multicell output.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
This article discusses four methods for overlaying images in a container on a web page
The viewer will learn how to count occurrences of each item in an array.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question