FPDF Word Wrap columns automatically as needed

I’m creating a PHP sales report using FPDF, but the customer’s name overlaps into the other columns.

image

How would I transform this code:

<?php

require("fpdf/fpdf.php");
include("../dbconnect.php");

class Report extends FPDF {
	function header() {
		$this->Image('../../img/casco_seal.png', 10, 6, 25, 25);
		$this->SetFont('Arial', 'B', 14);
		$this->Cell(265, 5, 'Casco Signs Inc.', 0, 0, 'C');
		$this->Ln();
		$this->SetFont('Arial', '', 12);
		$this->Cell(265, 10, 'Sales Report | ' . date("F Y"), 0, 0, 'C');
		$this->Ln(25);
	}

	function footer() {
		$this->SetY(-15);
		$this->SetFont('Arial', '', 9);
		$this->Cell(0, 10, 'Page '. $this->PageNo(), 0, 0,'R');
	}

	function headerSummary() {
		$x = $this->GetX();
		$this->SetX(15);
		$this->SetFont('Arial', 'B', 11);
		$this->Cell(20, 10, 'SP', 1, 0, 'C');
		$this->Cell(20, 10, 'Cust. #', 1, 0, 'C');
		$this->Cell(70, 10, 'Name', 1, 0, 'C');
		$this->Cell(25, 10, 'Sales', 1, 0, 'C');
		$this->Cell(27, 10, 'Extra Charge', 1, 0, 'C');
		$this->Cell(27, 10, 'Sales Tax', 1, 0, 'C');
		$this->Cell(30, 10, 'Total > $1000', 1, 0, 'C');
		$this->Cell(30, 10, 'Total < $1000', 1, 0, 'C');
		$this->Ln();
		$this->SetX($x);
	}

	function viewSummary() {
		$this->SetFont('Arial', '', 10);
		global $pdo;
		$sql = "SELECT Salesperson_1 as salesman, Customer_Number as customer, Customer_Name as name, SUM(Sales_Amount) as invoiced_sales, Extra_Charge_Amount as extra_charge, Tax_Amount as tax, SUM(CASE WHEN Sales_Amount > 1000 THEN Sales_Amount ELSE 0 END) as total_above_1000, SUM(CASE WHEN Sales_Amount < 1000 THEN Sales_Amount ELSE 0 END) as total_below_1000 FROM invoices GROUP BY Salesperson_1, Customer_Number WITH ROLLUP";
		$stmt = $pdo->prepare($sql);
		$stmt->execute();
		while($data = $stmt->fetch(PDO::FETCH_OBJ)) {
			$x = $this->GetX();
			$this->SetX(15);
			$this->Cell(20, 10, $data->salesman, 1, 0, 'C');
			$this->Cell(20, 10, $data->customer, 1, 0, 'C');
			$this->Cell(70, 10, $data->name, 1, 0, 'C');
			$this->Cell(25, 10, $data->invoiced_sales, 1, 0, 'C');
			$this->Cell(27, 10, $data->extra_charge, 1, 0, 'C');
			$this->Cell(27, 10, $data->tax, 1, 0, 'C');
			$this->Cell(30, 10, $data->total_above_1000, 1, 0, 'C');
			$this->Cell(30, 10, $data->total_below_1000, 1, 0, 'C');
			$this->Ln();
			$this->SetX($x);
		}
	}
}

$pdf = new Report();
$pdf->SetTitle('CascoTax | Sales Report');
$pdf->AliasNbPages();
$pdf->AddPage('L', 'Letter', 0);
$pdf->headerSummary();
$pdf->viewSummary();
$pdf->Output('I', date("F Y") . ' ' . 'Sales Report.pdf');

?>

to make the “Name” column (or $this->Cell(70, 10, $data->name, 1, 0, 'C'); )word wrap automatically?

I know I have to use MultiCell(); somewhere, but I can’t figure out how to do it.
I’ve also tried using this GitHub file with no luck.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.