pdf = new reportPDF('P', 'in', 'letter'); $this->pdf->SetMargins(.3, .3); $this->pdf->SetAutoPageBreak(true, .5); $this->pdf->AddPage(); $this->pdf->SetFont('arial', 'B', '10'); $headerText = auditionSetting('auditionName').' - Room and Judge Assignments'; $this->pdf->Cell(0, .2, $headerText, 1, 1, 'C'); $this->pdf->Ln(.1); $this->pdf->SetFont('arial', 'B', '10'); /* TABLE HEADER */ $this->pdf->cell($this->col1width, $this->lineHeight, 'Room', 1); $this->pdf->cell($this->col2width, $this->lineHeight, 'Auditions', 1); $this->pdf->cell(0, $this->lineHeight, 'Judges', 1, 1); $rooms = Room::withCount('entries')->where('id', '>', 0)->with('auditions')->with('judges')->get(); foreach ($rooms as $room) { $this->roomRow($room); } $this->pdf->Output('D', 'JudgingAssignments.pdf'); } private function roomRow(Room $room) { $this->pdf->SetFont('arial', '', '9'); $roomDescription = $room->name.' ('.$room->entries_count.')'; $judgingAssignments = $room->judges; $auditions = $room->auditions()->withCount('entries')->get(); $numLines = max([$judgingAssignments->count(), $auditions->count()]); $rowHeight = $this->lineHeight * $numLines; $auditionText = ''; $judgeText = ''; foreach ($auditions as $audition) { $auditionText .= $audition->name.' ('.$audition->entries_count.')'; $auditionText .= PHP_EOL; } foreach ($judgingAssignments as $ja) { $judgeText .= $ja->full_name(); $judgeText .= PHP_EOL; } if ($this->pdf->GetY() + $rowHeight > $this->pdf->getPageBreakTrigger()) { $this->pdf->AddPage(); } $startx = $this->pdf->getX(); $starty = $this->pdf->getY(); /* CELL BORDERS */ $this->pdf->MultiCell($this->col1width, $rowHeight, ' ', 1, 'C'); $this->pdf->SetXY($startx + $this->col1width, $starty); $this->pdf->MultiCell($this->col2width, $rowHeight, ' ', 1); $this->pdf->SetXY($startx + $this->col1width + $this->col2width, $starty); $this->pdf->MultiCell(0, $rowHeight, ' ', 1); /* CELL CONTENTS */ $this->pdf->SetXY($startx, $starty); $this->pdf->MultiCell($this->col1width, $this->lineHeight, $roomDescription, 0, 'C'); $this->pdf->SetXY($startx + $this->col1width, $starty); $this->pdf->MultiCell($this->col2width, $this->lineHeight, $auditionText); $this->pdf->SetXY($startx + $this->col1width + $this->col2width, $starty); $this->pdf->MultiCell(0, $this->lineHeight, $judgeText, 0); /* SET LOCATION FOR NEXT ROW */ $this->pdf->setXY($startx, $starty + $rowHeight); } } class reportPDF extends FPDF { public function getPageBreakTrigger() { return $this->PageBreakTrigger; } }