3

Looking for brilliant mind to help me fix my problem. I have inherited a Laravel v5.3 project, and the project should be able to pass CV's from html to .pdf. They have been using spatie/browsershot for that task. But for some reason the package won't write the damn file. I have been looking at the html passed to the function, and it all checks out. So I went to the guide on Github and put this line of code into the codefile as the only one left in the function.

Browsershot::html('<h1>Hello world!!</h1>')->save('example.pdf');

No matter what I do, I get this error message:

 Spatie \ Browsershot \ Exceptions \ CouldNotTakeBrowsershot
For some reason Chrome did not write a file at `example.pdf`.

I have also tried giving an absolute path for Browsershot to save the file at. But no matter. I have looked up many different guides the past two weeks, but nothing seems to work atm. Puppeteer is also installed locally.

I'm running a Windows 10 machine btw, with latest updates, if that matters.

Teambit
  • 185
  • 2
  • 9
  • Did you try with other browser ? Maybe you have to allow your browser to download some files or something like that. Try firefox, IE, any other you have available. – matiaslauriti Apr 06 '21 at 14:58
  • Just tried it with the brwosers at my disposal. No luck i'm afraid. Thanks for the fresh idea though ;) – Teambit Apr 06 '21 at 15:12
  • You will have to browse to the vendor file and `dd($targetPath)`, see this [source file](https://github.com/spatie/browsershot/blob/94815d30e61dfe0f833fe705c82f6c27b484041f/src/Browsershot.php#L561-L572). – matiaslauriti Apr 06 '21 at 15:30
  • Thanks mate, but the save path, don't seem to be the issue. – Teambit Apr 08 '21 at 14:24
  • Strange, because the source file is giving you the error when `file_exists` is false, so what is the value of the variable ? – matiaslauriti Apr 09 '21 at 00:11
  • Well thats just it. The path is just 'example.pdf'. – Teambit Apr 22 '21 at 09:15
  • have you installed puppeteer? if not then install it using `npm install puppeteer` and check the requirements for [Browsershot](https://github.com/spatie/browsershot#requirements). – Haritsinh Gohil May 29 '21 at 13:58

3 Answers3

3

I had the same issue in a PHP project. Installing the puppeteer package worked for me.

npm install puppeteer

1

I had yesterday the same problem. I have now solved it by using a specific version of puppeteer and that works.

npm install puppeteer@^14.2.1
Gregga17
  • 148
  • 7
0

Make sure you are using the latest node version.

blackgreen
  • 34,072
  • 23
  • 111
  • 129
Gamal Anwar
  • 49
  • 1
  • 6