<?php
require 'vendor/autoload.php';

use Dompdf\Dompdf;
use Dompdf\Options;

$options = new Options();
$options->set('isRemoteEnabled', true);
$dompdf = new Dompdf($options);

// Get image content and convert to base64
$imagePath = realpath('./OHSC_certificates.jpg');
if (!$imagePath) {
    die('Image not found.');
}

$imageData = base64_encode(file_get_contents($imagePath));
$imageMimeType = mime_content_type($imagePath);

// Set image to A4 size (in points, 595x842 at 72 DPI)
$html = '
<style>
  body, html {
    margin: 0;
    padding: 0;
  }
  .full-page {
    width: 595pt;
    height: 842pt;
    object-fit: cover;
  }
</style>
<img class="full-page" src="data:' . $imageMimeType . ';base64,' . $imageData . '" />
';

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