mPDF error: Unable to create output file
Try not to modify the source. Instead, revert back to fopen($file_out,'wb');
and make sure that folder permissions are set to 0777
, like you did.
Also, check if you're using the absolute path in order to write to a file, rather than using relative paths or even worse, URL.
So,
$file = "/var/www/html/mywebsite/mypdfs/myfile.pdf";
and try if it works.
Good luck!