Access to node files for spatie/browsershot to create PDF files #80
betsyecastro
started this conversation in
General
Replies: 2 comments
-
Not sure, but I would suggest creating a config and .env setting for it. If you can apply the |
Beta Was this translation helpful? Give feedback.
0 replies
-
Ok, this is how I did it and it works. public function pdfExport(Profile $profile, $include_path = false) {
if (!$include_path) {
try {
$pdf_content = Browsershot::url($profile->url)
->setExtraHttpHeaders(['Paginated' => '0'])
->pdf();
} catch (ProcessFailedException $e) {
$this->pdfExport($profile, true);
}
}
$pdf_content = Browsershot::url($profile->url)
->setIncludePath(env('BROWSERSHOT_NODE_MODULES'))
->setExtraHttpHeaders(['Paginated' => '0'])
->pdf();
return response($pdf_content)->header('Content-Type', 'application/pdf');
} And, as @gab3 suggested, I used the relative path for the BROWSERSHOT_NODE_MODULES setting, in the .env file: BROWSERSHOT_NODE_MODULES="~/.nvm/versions/node/v16.15.1/bin" Thank you both! |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
In our staging and production environment, do we need to specify the binary path to give spatie/browsershot (package to generate PDF files https://spatie.be/docs/browsershot/v2/usage/creating-pdfs) access to the node modules?
To render a PDF file locally, I had to do it with the Browsershot option setIncludePath like so:
https://spatie.be/docs/browsershot/v2/requirements
Thank you :)
Beta Was this translation helpful? Give feedback.
All reactions