<?php
// generate-pdf.php - Generates a PDF version of the current session form
session_start();

if (!isset($_SESSION['form_data'])) {
  die("No form data to generate PDF.");
}

require_once __DIR__ . '/assets/dompdf/autoload.inc.php';
use Dompdf\Dompdf;

ob_start();
$form = $_SESSION['form_data'];
include 'template-review-pdf.php';
$html = ob_get_clean();

$dompdf = new Dompdf();
$dompdf->loadHtml($html);
$dompdf->setPaper('A4', 'portrait');
$dompdf->render();
$dompdf->stream('Tartu-Summer-Application.pdf', ["Attachment" => false]);
exit();
