Solved

FPDF MultiCell wrapping issue

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Test if unique ID is in log file 5 31
if (is_singular not working 5 37
PHP delete contents of file- before writing to it 6 49
Pull Variable from URL  Use php template 1 30
This article discusses how to create an extensible mechanism for linked drop downs.
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
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…
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.

679 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