SetFont('Arial', 'B', 15); $this->Cell(0, 10, 'Employee Report', 0, 1, 'C'); $this->Ln(10); } // Table generation function function CreateTable($header, $data) { // 1. Column Widths $w = array(30, 50, 50, 40); // 2. Header Style $this->SetFillColor(232, 232, 232); // Light Gray Background $this->SetTextColor(0); // Black Text $this->SetFont('Arial', 'B', 12); // Bold Font // Print Header Rows for($i = 0; $i < count($header); $i++) { // Cell(Width, Height, Text, Border, Position, Alignment, Fill) $this->Cell($w[$i], 7, $header[$i], 1, 0, 'C', true); } $this->Ln(); // Move to next line // 3. Data Rows Style $this->SetFont('Arial', '', 12); // Regular font for data // Print Data Rows foreach($data as $row) { $this->Cell($w[0], 6, $row[0], 1, 0, 'C'); $this->Cell($w[1], 6, $row[1], 1, 0, 'L'); $this->Cell($w[2], 6, $row[2], 1, 0, 'L'); $this->Cell($w[3], 6, '$' . number_format($row[3]), 1, 0, 'R'); // Right align currency $this->Ln(); // Move to next line } } } // Instantiate and build the PDF $pdf = new PDF(); $pdf->AddPage(); // Column headers $header = array('ID', 'First Name', 'Last Name', 'Salary'); // Sample Data Array (Can be pulled dynamically from a database) $data = array( array('101', 'John', 'Doe', 45000), array('102', 'Jane', 'Smith', 52000), array('103', 'Robert', 'Johnson', 61000), ); $pdf->CreateTable($header, $data); $pdf->Output('I', 'report.pdf'); // View in browser ?>