Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create multicell table FPDF

Tags:

php

fpdf

I wrote following code to create a table with multicell

$this->Cell(25, 25, "SR.No.", 'LTRB', 0, 'L', true);
    $this->Cell(60, 25, "CHALLAN", 'LTRB', 0, 'L', true);
    $this->Cell(300, 25, "JOB NAME", 'LTRB', 0, 'L', true);
    $this->Cell(60, 25, "QTY.", 'LTRB', 0, 'L', true);
    $this->Cell(60, 25, "RATE", 'LTRB', 0, 'L', true);
    $this->Cell(90, 25, "AMOUNT", 'LTRB', 1, 'C', true);
    $i=1;
    while($row  =   mysql_fetch_array($result))
    {
    $x = $this->x;
    $y = $this->y;
    $push_right = 0;
    $this->MultiCell($w = 25,25,$i,1,'C',0);
    $push_right += $w;
    $this->SetXY($x + $push_right, $y);
    $this->MultiCell($w = 60,25,$row[3],1,'C',0);
    $push_right += $w;
    $this->SetXY($x + $push_right, $y);
    $this->MultiCell($w = 300,25,$row[2],1,'L',0);
    $push_right += $w;
    $this->SetXY($x + $push_right, $y);
    $this->MultiCell($w = 60,25,$row[4],1,'L',0);
    $push_right += $w;
    $this->SetXY($x + $push_right, $y);
    $this->MultiCell($w = 60,25,$row[5],1,'L',0);
    $push_right += $w;
    $this->SetXY($x + $push_right, $y);
    $this->MultiCell($w=90,25,$row[6],1,'C',1);
    $this->Ln();
    $i++;
    }

My code generating this output enter image description here

Bu that is not align i want to remove space from both row and equal height of each column tried many time but didnt resolved.

like image 568
prameshwer Avatar asked May 04 '26 14:05

prameshwer


1 Answers

You have used Multicell. Multicell's height is according to line, not box.And Cell's height is according to box. Hence, text came up in 2 lines and height become 50px (25*2) and remaining cell is of height 25px. Use cell of height 50px (in your case) instead of multicell if content is static or use multicell if the content is dynamic and calculate height accordingly. For ex:- your box height become 50px. So for remaining multicell, set height to 50px.

like image 52
Rupal Avatar answered May 06 '26 03:05

Rupal