Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
16.67% |
1 / 6 |
|
0.00% |
0 / 1 |
CRAP | |
0.00% |
0 / 1 |
| Html2PdfService | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 1 |
| render | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace UppServices; |
| 6 | |
| 7 | require_once __DIR__.'/../../../vendor/autoload.php'; |
| 8 | |
| 9 | use Dompdf\Dompdf; |
| 10 | |
| 11 | /** |
| 12 | * Reusable HTML-to-PDF renderer for Slim services/actions. |
| 13 | */ |
| 14 | class Html2PdfService |
| 15 | { |
| 16 | /** |
| 17 | * Render HTML into a PDF binary string. |
| 18 | * |
| 19 | * @param string $html HTML fragment/body content. |
| 20 | * @param string $paper Paper size (for example A4, letter). |
| 21 | * @param string $orientation Orientation (portrait|landscape). |
| 22 | * @return string PDF binary output. |
| 23 | */ |
| 24 | public function render(string $html, string $paper = 'A4', string $orientation = 'portrait'): string |
| 25 | { |
| 26 | $dompdf = new Dompdf(); |
| 27 | $dompdf->loadHtml("<!DOCTYPE html><html><head><meta charset='utf-8'></head><body>".$html."</body></html>", 'UTF-8'); |
| 28 | $dompdf->setPaper($paper, $orientation); |
| 29 | $dompdf->render(); |
| 30 | |
| 31 | return $dompdf->output(); |
| 32 | } |
| 33 | } |