2

I created a table using FPDF and the Cell method. This worked great but each column had a set width which caused several problems as the table exceeded the right page margin and also the Product Name would overlap the product price, making it impossible to read.

After researching the issue on Google and Stack, I changed my code to MultiCell but each column now has an entire row. I have provided a picture of the Cell and MultiCell table and also provided the code for each method.

I hope one of you can help.

Thanks.

MultiCell: enter image description here

Cell: enter image description here

Code for Cell method:

class PDF extends FPDF {    
    function LoadData($file) {
        $lines = file($file);
        $data = array();
        foreach($lines as $line)
        $data[] = explode(';', trim($line));
        return $data;
    }

    function BasicTable($header, $data) {
        $nameIndex =  array_search ('Name', $header);       

        foreach($header as $key => $col) {
            $width = ($key == $nameIndex) ? 80 : 40;
            $this->Cell($width, 7, $col, 1);            
        }

        $this->Ln();

        foreach($data as $row) {
            foreach($row as $key => $col) {
                $width = ($key == $nameIndex) ? 80 : 40;
                $this->Cell($width, 6, $col, 1);
            }

            $this->Ln();
        }
    }
}

Code for MultiCell method:

class PDF extends FPDF {    
    function LoadData($file) {
        $lines = file($file);
        $data = array();
        foreach($lines as $line)
        $data[] = explode(';', trim($line));
        return $data;
    }

    function BasicTable($header, $data) {
        $nameIndex =  array_search ('Name', $header);       

        foreach($header as $key => $col) {
            $this->MultiCell($width, 7, $col, 1);            
        }

        $this->Ln();

        foreach($data as $row) {
            foreach($row as $key => $col) {
                $this->MultiCell($width, 6, $col, 1);
            }

            $this->Ln();
        }
    }
}

1 Answers1

0

if possible, you can refer FPDF linebreak in PHP. but it's not used cell or multicell. It's used ROW. ROW Contains multicell.

rsmdh
  • 128
  • 1
  • 2
  • 12