<?php
// defined('BASEPATH') OR exit('No direct script access allowed');

function generate_pdf($html, $filename, $paper = 'A4', $orientation = 'portrait')
{
    require_once APPPATH.'Libraries/dompdf/autoload.inc.php';

    $dompdf = new Dompdf\Dompdf();
    $dompdf->loadHtml($html);
    $dompdf->setPaper($paper, $orientation);
    $dompdf->render();
    // $dompdf->stream($filename . '.pdf', array('Attachment' => 0));
    $pdfContent = $dompdf->output();
    $pdfFilePath = 'uploads/pdf/'.$filename.'.pdf';
    file_put_contents($pdfFilePath, $pdfContent);
}
