I want to create a something which could work like dynamic table. Could because I knew how many cells it would be, but kind of because content I put into cell could be different length. I have used code posted of fpdf
site:
require('fpdf/fpdf.php');
class PDF extends FPDF{
function BasicTable($header, $data)
{
// Header
foreach($header as $col)
$this->Cell(40,7,$col,1);
$this->Ln();
// Data
foreach($data as $row)
{
foreach($row as $col)
$this->Cell(40,6,$col,1);
$this->Ln();
}
}
}
and right now if i put into Table those values:
$header = array('Country', 'Capital', 'Area (sq km)', 'Pop. (thousands)');
$data = array(array('a','a','a','a'), array('a','a','a','a'), array('a','a','a','a'), array('a','a','a','a'));
$pdf->SetY(45);
$pdf->BasicTable($header,$data);
everything is ok. But when I want to change my 'a'
into something more complex, like sentence made of few words, my text is 'leaving' the cell and it start to overlap the next cell.
Is there a way in fpdf to autofit cell?
You have to use FPDF::MultiCell() method, which is used to display multiline content.
In MultiCell, text will wrap and you won't have that problem.
You could also look at abstraction code over FPDF like PDML, or HTML2FPDF, or maybe TCPDF as stated before but i don't know this one.
Good luck with your project.