0
I have a laravel 10 app. In my index.blade.php I have list of workers, each of whom has a separate view page, in index.blade.php I have a print button, which on click should print the pdf version of the separate blade view page of the worker. Since dompdf doesn't support Arabic, flexbox etc. I thought of using browsershot by spatie.
I followed instructions as per documenation here: https://github.com/spatie/browsershot
And sadly what could've been so simple has made me crazy with one issue after another.
All seem to be related to puppeteer.
My latest error message is:
Symfony
\
Component
\
Process
\
Exception
\
ProcessFailedException
PHP 8.2.0
10.24.0
The command ""C:\Program Files\nodejs\node.exe" "C:\xampp\htdocs\appname\appname\vendor\spatie\browsershot\src/../bin/browser.cjs" "{""url"":""http://localhost:8000/admin/workers/3"",""action"":""pdf"",""options"":{""args"":[],""viewport"":{""width"":800,""height"":600},""newHeadless"":true}}"" failed. Exit Code: 1(General error) Working directory: C:\xampp\htdocs\appname\appname\public Output: ================ Error Output: ================ TimeoutError: Navigation timeout of 30000 ms exceeded at Timeout. (C:\xampp\htdocs\boom\boom\node_modules\puppeteer-core\lib\cjs\puppeteer\util\Deferred.js:27:33) at listOnTimeout (node:internal/timers:564:17) at process.processTimers (node:internal/timers:507:7) ERROR: The process "40040" not found.
Kindly not the process number is different each time.
Before that, I had another error:
Error: ENOENT: no such file or directory, mkdtemp 'undefined\temp\puppeteer_dev_chrome_profile-XXXXXX'] { errno: -4058, code: 'ENOENT', syscall: 'mkdtemp', path: 'undefined\temp\puppeteer_dev_chrome_profile-XXXXXX' }
I'm on Windows 10, [email protected], node v18.13.0,npm 8.19.3.
I don't understand what's causing this, can't find anything on other stackoverflow or laracast answer.
Please help.
My controller code:
public function generatePdfPreview($id)
{
$worker = Worker::findOrFail($id);
// Use Browsershot to capture the web page and save it as a PDF
$pdf = Browsershot::url(route('admin.workers.show', $worker->id))
->setNodeBinary("C:\Program Files\nodejs\node.exe")
->setOption('newHeadless', true)
->pdf();
return response($pdf)->header('Content-Type', 'application/pdf');
}