Solved

FPDF MultiCell wrapping issue

Posted on 2011-02-13
1
2,773 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
1 Comment
 
LVL 27

Accepted Solution

by:
Lukasz Chmielewski earned 500 total points
Comment Utility
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

Easy Project Management (No User Manual Required)

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
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…
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

728 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now