Error generating PDF with phantom js on shared hosting


I installed v5 on a shared hosting within a subdomain, at first I was able to generate PDF, but after customizing a template I started to receive:
error 500: There was an error generating the PDF with Phantom JS
when previewing a PDF
and the error:
There was an error loading the PDF document
when trying to customize a template.

I already tried changing to snappdf in the .env file.

But I kept getting the same thing:
error 500 generating the PDF with Phantom JS.

Then I went back to phantom js and used an api-key to increase the limit to 500, but I still get the same error. Right now I have it like this

2022-02-08 21.10.28 b1bf4918ebd1

And this is the only error in the laravel.log file, even when I use snappdf:

production.ERROR: There was an error generating the PDF with Phantom JS {“exception”:"[object] (AppExceptions/PhantomPDFFailure(code: 0): There was an error generating the PDF with Phantom JS at /home/user/routetoinvoiceninja/app/Utils/PhantomJS/Phantom.php:150)

I hope you can help me.


Did you run php artisan optimize after updating the .env file?

try hosted_ninja it works perfect for me

You’ll need a white label license for that.


Unfortunately, I don’t have access to the console.

So try to do it by adding this route

Route::get('/optimize', function() {
    $exitCode = Artisan::call('optimize'); 
    return 'optimized!';

But I get a 404 error when I enter the path in my browser:

It may work to load /update?secret= in the browser.

You can check if the change has taken effect using the health check option in the about dialog.

I tried it, but it doesn’t seem to work.
I changed the PDF generation to snappdf to test if anything changes, but with both settings I get

2022-02-09 12.13.32

And I still can’t generate PDF

@david is deleting the bootstrap/cache folder an option if loading /update doesn’t work?


yes, clearing the contents of bootstrap/cache is equivalent to /update

Thank you! @hillel @david
This worked!
more or less

Sometimes when previewing the PDF customization it throws me an error, but when generating an invoice in the production environment it seems to work fine and for the customization I can always use the HTML view

I purchased the white label but my site is still throwing error due to PDF.

Have you set hosted_ninja as the PDF option in the .env file?