render((array) $invoice->snapshot); } /** @param array $snapshot */ public function render(array $snapshot): string { $issuer = (array) ($snapshot['issuer'] ?? []); $pdf = new InvoiceDocument('P', 'mm', 'A4', true, 'UTF-8'); $pdf->setIssuer($issuer, $this->logoFile($issuer), __('invoice.page')); $pdf->SetCreator('CluPilot'); $pdf->SetAuthor((string) ($issuer['name'] ?? '')); $pdf->SetTitle((string) ($snapshot['meta']['number'] ?? '')); // Room at the bottom for the four-column footer, which is fixed height // and would otherwise be written over the last line of the table. $pdf->SetMargins(20, 34, 20); $pdf->SetAutoPageBreak(true, 34); $pdf->SetFont('dejavusans', '', 9); $pdf->AddPage(); // Rendered from a Blade template: a table of line items expressed as // Cell() calls with millimetre coordinates is a table nobody will ever // adjust, and this one has to be adjusted the first time somebody sees // it on paper. $pdf->writeHTML( View::make('pdf.invoice', ['s' => $snapshot])->render(), true, false, true, false, '' ); return $pdf->Output('', 'S'); } /** * The logo on disk, or nothing. * * Nothing is a perfectly good answer: an invoice without a logo is still a * valid invoice, and refusing to render one because an image is missing * would block the only document that actually has to exist. * * @param array $issuer */ private function logoFile(array $issuer): string { $path = trim((string) ($issuer['logo_path'] ?? '')); if ($path === '') { return ''; } $full = Storage::disk('public')->path($path); return is_file($full) ? $full : ''; } }