8

I trying to create a custom table using FPDF Cell/MultiCell.

My 1st cell is a MultiCell that has two lines of text. The next cell should then just be placed right next to it.

Problem : no matter what I do to the next cell, it is always on the next line of the page instead of being placed right next to the 1st cell - and it's driving me crazy.

Here is my code:

require_once 'config.php';
require 'fpdf.php';

$pdf = new FPDF();
$pdf->AddPage();
$pdf->SetFont('Arial','',10);
$pdf->MultiCell(150,10,'Certificate of foreign Currency usage in respect of materials and components in terms of the notes to rebate item ',1);
$pdf->SetFont('Arial','',10);
$pdf->MultiCell(40,10,'DA190',1);
$pdf->Output();

The cell containing the text "DA190" should be placed next to the previous cell, but is being positioned underneath the previous cell.

Jonathan Hall
  • 75,165
  • 16
  • 143
  • 189
Pierre Pretorius
  • 461
  • 3
  • 8
  • 16

3 Answers3

16

Before printing your first multicell, record the cursor position:

$x=$this->GetX();
$y=$this->GetY();

add your multicell using $this->Multicell($w,5,'Content');

Reset the cursor position to the start height (y) and the start horizontal + the width of the 1st multicell:

$this->SetXY($x+$w,$y);

Add your next multicell and repeat as necessary.

powtac
  • 40,542
  • 28
  • 115
  • 170
user2871008
  • 161
  • 1
  • 3
  • $w is undefined – Emmac Jun 06 '18 at 17:34
  • $w is defined. It is the width of the previous cell. If you use MultiCell(123,6,'content'); You can also just use $this->SetXY($x+123,$y); if you dont use a variable for the MultiCell width. – Maarten Sep 08 '20 at 09:54
5

this worked for me

$pdf->multicell(120, 5, '   ' . $actividad, 0, 'l', true);
$x = $pdf->GetX();
$y = $pdf->GetY();
$pdf->SetXY($x + 120, $y);
$pdf->Cell(70, -5, '   ' . $claseActividad, '', 0, 'l', true);

result

-5

I found the solution - fpdf has an extension (#3) focussed on using multicells.

Pierre Pretorius
  • 461
  • 3
  • 8
  • 16
  • 2
    Can you explain this answer a little bit more? What needs to be added to make the 3 cells fit into one row ? Here is your modified [code](http://pastebin.com/0vmfSTP4). – Vucko Apr 29 '13 at 18:14