<?php namespace App\Services; class SimplePdfService {public function render(array $lines):string{$esc=fn($s)=>str_replace(['\\','(',')'],['\\\\','\\(','\\)'],(string)$s);$y=790;$content="BT /F1 11 Tf 50 $y Td ";foreach($lines as $i=>$line){if($i)$content.="0 -18 Td ";$content.='('.$esc(mb_strimwidth((string)$line,0,100,'…')).') Tj ';}$content.="ET";$objs=[];$objs[]="<< /Type /Catalog /Pages 2 0 R >>";$objs[]="<< /Type /Pages /Kids [3 0 R] /Count 1 >>";$objs[]="<< /Type /Page /Parent 2 0 R /MediaBox [0 0 595 842] /Resources << /Font << /F1 5 0 R >> >> /Contents 4 0 R >>";$objs[]="<< /Length ".strlen($content)." >>\nstream\n$content\nendstream";$objs[]="<< /Type /Font /Subtype /Type1 /BaseFont /Helvetica >>";$pdf="%PDF-1.4\n";$offset=[0];foreach($objs as $i=>$o){$offset[]=strlen($pdf);$pdf.=($i+1)." 0 obj\n$o\nendobj\n";}$xref=strlen($pdf);$pdf.="xref\n0 ".(count($objs)+1)."\n0000000000 65535 f \n";for($i=1;$i<=count($objs);$i++)$pdf.=sprintf('%010d 00000 n ',$offset[$i])."\n";$pdf.="trailer << /Size ".(count($objs)+1)." /Root 1 0 R >>\nstartxref\n$xref\n%%EOF";return $pdf;}}