<?php

namespace App\Libraries;

use Dompdf\Dompdf;
use Dompdf\Options;

/**
 * Thin wrapper around dompdf — renders an HTML view string to a PDF byte
 * string. Kept as one shared library rather than calling Dompdf directly
 * from controllers, so paper size/options stay consistent across the
 * per-folio invoice and the corporate monthly statement.
 */
class PdfService
{
    public function renderHtml(string $html, string $paperOrientation = 'portrait'): string
    {
        $options = new Options();
        $options->set('isRemoteEnabled', false); // no external network fetches from generated HTML
        $options->set('defaultFont', 'Helvetica');

        $dompdf = new Dompdf($options);
        $dompdf->loadHtml($html);
        $dompdf->setPaper('A4', $paperOrientation);
        $dompdf->render();

        return $dompdf->output();
    }
}
