<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);

/* PHP 8 + Dompdf fix */
if (!function_exists('mb_internal_encoding')) {
    function mb_internal_encoding($enc = null) {
        return 'UTF-8';
    }
}

require_once __DIR__ . '/dompdf/autoload.inc.php';

use Dompdf\Dompdf;
use Dompdf\Options;

$options = new Options();
$options->set('isRemoteEnabled', true);
$options->set('defaultFont', 'DejaVu Sans');

$dompdf = new Dompdf($options);

$html = '
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
</head>
<body>
<h2>Dompdf WORKING ✅</h2>
<p>PHP 8.2 compatible version confirmed.</p>
</body>
</html>
';

$dompdf->loadHtml($html);
$dompdf->setPaper("A4", "portrait");
$dompdf->render();
$dompdf->stream("success.pdf", ["Attachment" => false]);
exit;
