I’m using Spatie/Browsershot in Laravel to generate PDFs in Base64 format. In my local machine (Windows), it works without any issues. However, in my Ubuntu server (AWS), it doesn’t. It just prints out some numbers which I believe to be raw binary data.
The code I’m using for my local host:
$base64Data = Browsershot::html(view('receipt-pdf', ['data' => $receipt, 'pmData' => $pmData])->render())
->setNodeBinary("C:\Program Files\nodejs\node")
->setNpmBinary("C:\Program Files\nodejs\npm")
->setChromePath('C:\Program Files\Google\Chrome\Application\chrome.exe')
->format('A4')
->base64pdf();
Example output:
JVBERi0xLjQKJdPr6eEKMSAwIG9iago8PC9UaXRsZSAoQXFhcmkgLSA3KQovQ3JlYXRvciAoTW96aWxsYS81LjAgXChXaW5kb3dzIE5UIDEwLjA7IFdpbjY0OyB4NjRcKSBBcHBsZVdlYkt...
And for my Ubuntu server:
$base64Data = Browsershot::html(view('receipt-pdf', ['data' => $receipt, 'pmData' => $pmData])->render())
->setChromePath('/usr/bin/google-chrome-stable')
->format('A4')
->base64pdf();
Example output:
37,80,68,70,45,49,46,52,10,37,211,235,233,225,10,49,32,48,32,111,98,106,10,60,60,47,84,105,116,108,......
I have checked the following:
- Permissions regarding the execution of Chrome.
- Using Chromium instead of Chrome.
- Re-installing Chrome.
- Generating with ->pdf() instead of ->base64pdf() and then using base64_encode().
None of those worked.
Hussam is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.