Solved

FPDF MultiCell wrapping issue

Posted on 2011-02-13
1
2,855 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 500 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

Why Off-Site Backups Are The Only Way To Go

You are probably backing up your data—but how and where? Ransomware is on the rise and there are variants that specifically target backups. Read on to discover why off-site is the way to go.

Question has a verified solution.

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

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this. Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it i…
This article discusses four methods for overlaying images in a container on a web page
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

691 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