Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: Not supported for windows #70

Closed
christmex opened this issue Feb 3, 2024 · 9 comments
Closed

[Bug]: Not supported for windows #70

christmex opened this issue Feb 3, 2024 · 9 comments
Labels
bug Something isn't working

Comments

@christmex
Copy link

What happened?

I want to use the laravel pdf, preview it or even download it, but I can't download or even preview the PDF, it keeps getting errors, like this
image

*Additional information
Node Version: v21.6.1
Npm Version: 10.4.0

How to reproduce the bug

use Spatie\LaravelPdf\Facades\Pdf;
//....
Route::get('/print',function(){
    //already had the tes blade file inside resource/views
    Pdf::view('tes', ['invoice' => 'as'])
        ->format('a4')
        ->save('invoice.pdf');
});

I'm using this basic code just for trying but it keep getting the error

Package Version

1.1.2

PHP Version

8.2.10

Laravel Version

10.42.0

Which operating systems does with happen with?

Windows

Notes

No response

@christmex christmex added the bug Something isn't working label Feb 3, 2024
@zaidpirwani
Copy link

facing same issue
node, v20.9.0
npm, v10.1.0
php, v8.2.4
laravel, v10.43.0
laravel-pdf, v1.1.2
Windows 11 Pro, version 23H2
PhpStorm 2023.3.3, Build #PS-233.14015.96, built on January 24, 2024

node available in windows path, accessible from cmd prompt / terminal

@zaidpirwani
Copy link

got a new error by adding withbrowsershot, found this by diving into the code, found it later in the docs and adding setNodeBinary with path to node
return Pdf::view('pdf.purchaseOrder', [
'record' => $record,
'record_quote' => $record->quotes->where('is_selected', true)->first(),
])->format('A4')
->withBrowsershot(function (Browsershot $browsershot) {
$browsershot->setNodeBinary("C:/nodejs/node.exe");
})
->save($record->getPRNumber() . '.pdf');

Its a start, I will explore further and report

The command ""C:/nodejs/node.exe" "C:\Users\Zaid\PhpstormProjects\LaravelHello\vendor\spatie\browsershot\src/../bin/browser.cjs" "{""url"":""file://C:\Users\Zaid\AppData\Local\Temp\1346465607-0360706001706942517\index.html"",""action"":""pdf"",""options"":{""path"":""PR-2402-0001.pdf"",""args"":[],""viewport"":{""width"":800,""height"":600},""displayHeaderFooter"":false,""format"":""A4"",""printBackground"":true}}"" failed. Exit Code: 1(General error) Working directory: C:\Users\Zaid\PhpstormProjects\LaravelHello\public Output: ================ Error Output: ================ �[1m�[43m�[30m Puppeteer old Headless deprecation warning:�[0m�[33m In the near future headless: true will default to the new Headless mode for Chrome instead of the old Headless implementation. For more information, please see https://developer.chrome.com/articles/new-headless/. Consider opting in early by passing headless: "new" to puppeteer.launch() If you encounter any bugs, please report them to https://github.com/puppeteer/puppeteer/issues/new/choose.�[0m [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' }

@zaidpirwani
Copy link

upon further testing, it seems to concrn with puppeteer and some path related matter on windows

Browsershot::url('https://example.com')
->setNodeBinary("C:/nodejs/node.exe")
->setNpmBinary("C:/nodejs/node_modules/npm/bin")
->setNodeModulePath("C:/Users/Zaid/PhpstormProjects/LaravelHello/node_modules")
->setOption('newHeadless', true)
->save('a.png');

new error, same error shows when I use laravel-pdf, so the error is a bit more upstream...
The command ""C:/nodejs/node.exe" "C:\Users\Zaid\PhpstormProjects\LaravelHello\vendor\spatie\browsershot\src/../bin/browser.cjs" "{""url"":""https://example.com"",""action"":""screenshot"",""options"":{""type"":""png"",""path"":""a.png"",""args"":[],""viewport"":{""width"":800,""height"":600},""newHeadless"":true}}"" failed. Exit Code: 1(General error) Working directory: C:\Users\Zaid\PhpstormProjects\LaravelHello\public Output: ================ Error Output: ================ [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' }

though I would appreciate if any guidance and help is provided, am stuck on where to go now

@zaidpirwani
Copy link

zaidpirwani commented Feb 3, 2024

another update, running simple browsershot command in the terminal works

php artisan tinker
use Spatie\Browsershot\Browsershot;
Browsershot::url('https://example.com')->setOption('newHeadless', true)->save('a.pdf');

and also the below works as well in terminal

php artisan tinker
use Spatie\LaravelPdf\Facades\Pdf;
Pdf::html('<h1>Hello world!!</h1>')->save('invoice.pdf');

@zaidpirwani
Copy link

zaidpirwani commented Feb 3, 2024

after much code diving, it seemed that the process of puppeteer being run by browsershot was not getting any environment variables, I traced the process creation to line 1032 in file vendor/spatie/browsershot/src/Browsershot.php
$process = $this->isWindows() ? new Process($fullCommand) : Process::fromShellCommandline($fullCommand);

and modified

$process = $this->isWindows() ? new Process($fullCommand,null,getenv() ) : Process::fromShellCommandline($fullCommand);

now I am able to generate PDF Files. I know am not supposed to modify files in vendor folders - need to check further

also am sending the whole env of laravel, not sure if that is right or not - am currently running this locally.

Mentioned this here as well: spatie/browsershot#728

@freekmurze
Copy link
Member

This should be handled on Browsershot

@adrianojsle
Copy link

after much code diving, it seemed that the process of puppeteer being run by browsershot was not getting any environment variables, I traced the process creation to line 1032 in file vendor/spatie/browsershot/src/Browsershot.php $process = $this->isWindows() ? new Process($fullCommand) : Process::fromShellCommandline($fullCommand);

and modified

$process = $this->isWindows() ? new Process($fullCommand,null,getenv() ) : Process::fromShellCommandline($fullCommand);

now I am able to generate PDF Files. I know am not supposed to modify files in vendor folders - need to check further

also am sending the whole env of laravel, not sure if that is right or not - am currently running this locally.

Mentioned this here as well: spatie/browsershot#728

THANK YOUUUUUUU

@acharmat
Copy link

after much code diving, it seemed that the process of puppeteer being run by browsershot was not getting any environment variables, I traced the process creation to line 1032 in file vendor/spatie/browsershot/src/Browsershot.php $process = $this->isWindows() ? new Process($fullCommand) : Process::fromShellCommandline($fullCommand);

and modified

$process = $this->isWindows() ? new Process($fullCommand,null,getenv() ) : Process::fromShellCommandline($fullCommand);

now I am able to generate PDF Files. I know am not supposed to modify files in vendor folders - need to check further

also am sending the whole env of laravel, not sure if that is right or not - am currently running this locally.

Mentioned this here as well: spatie/browsershot#728

Thank you so much

you saved my day

@KahiluChipango
Copy link

Use this Instead

npm install puppeteer --location=global

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

6 participants