I've finally fixed my issue.
My initial function to generate the PDF's was:
class PdfVariable
{
public function generate($html, $name, $toBrowser = true)
{
try
{
$defaultConfig = (new \Mpdf\Config\ConfigVariables())->getDefaults();
$_mpdf = new \Mpdf\Mpdf([
'mode' => 'utf-8',
'format' => 'A4-P',
]);
$_mpdf->shrink_tables_to_fit = 1;
$_mpdf->WriteHTML($html);
if($toBrowser)
{
// Shows pdf in browser (for development)
//$_mpdf->Output($name . '.pdf', \Mpdf\Output\Destination::DOWNLOAD);
$_mpdf->Output();
}
else
{
// Downloads
$_mpdf->Output($name . '.pdf', \Mpdf\Output\Destination::DOWNLOAD);
}
}
catch(Exception $e)
{
echo $e->getMessage();
}
if($toBrowser)
{
exit(0);
}
}
}
Somehow this piece of code
if($toBrowser)
{
exit(0);
}
Causes it to crash when the environment is set to staging/production. If set to 'dev' it will still function normally with this piece of code.
Still find it weird it gave no errors whatsoever in the Craft CMS logs.
Hope I can help someone out with this.