I'm new to consoles stuff. My goal is to create a platform independent command line (windows, mac, linux) to convert an hmtl file to a pdf. I'm using to create the command Symfony Console Commands Version 6 (so I can easily run it on all operating systems) and to convert the HTML i am trying to use Dompdf.
I tried saving my HTML to a file and it worked.
$myhtmlfile = fopen($newDirectory . DIRECTORY_SEPARATOR . $fileName . ".html", "w") or die("Unable to create file!");
fwrite($myhtmlfile, $myhtml);
Now i want to save the html as PDF file with Dompdf.
$myhtml ='<html><body>'. '<p>I wand a PDF with this TEXT!</p>'. '</body></html>';
$dompdf = new DOMPDF();
$dompdf->loadhtml($myhtml);
$dompdf->render();
$output = $dompdf->output();
file_put_contents($newDirectory . DIRECTORY_SEPARATOR . $fileName. ".pdf" , $output);
But I suddenly get an error message "Permission denied"... Why can I save the HTML file but not this PDF? I'm trying to save them in the same directory created a few lines above the line where I create the HTML file.
// call command in terminal
C:\Users\...\app>php documentGenerator.php doc:GenerateDocu
// Result
PHP Warning: file_put_contents(C:\Users\...\generatedDocs\generated-documentation-2022-06-11-09-29-54\generated-documentation-2022-06-11-09-29-54.pdf): Failed to open stream: Permission denied in C:\Users\...\app\resources\generatePdf.php on line 68
Is there a (simple) solution for this that works on Windows, Mac and Linux?