[Error] Failed to load PDF document

I just tested Invoice Ninja v5.2.7-C51 installed on my shared hosting via Scriptaculous. Everything went smoothly and I could keep editing the header/footer of my invoices quite nicely. I generated the Preview of my PDF invoices maybe even more than 100 times successfully. Suddenly, every time I clicked on Preview to check my rendered Invoice, the Error notification appears on screen:

[Error] Failed to load PDF document.

I kept searching for my answer for quite awhile, but nothing so far seems to help. The hosting guys ran php artisan optimize for me. I cleared my cache in my Chromium browser, used CTRL+Reload button right after and I even used Incognito mode, but the error persists.

The storage/logs/laravel.log contains NO ERRORS, just bunch of [2021-07-03 18:19:10] production.INFO: https://localhost/public/index.php/tmp_pdf/i7gWpGIYA5jNfNKQGeLoDVPvw5jIVWoZ with different date/time and different hash. By the time of created logs I located the corresponding existing cache file located in /storage/framework/cache/data/9c/a9/9ca96703338aa31e785665f1ad732881775a3d58.

I also tried different Invoice Designs (Clean, Modern, Playful, etc.) with the default layout, but the Preview would always end up with the same error message: Failed to load PDF document.

What could cause this sudden behavior with no obvious reason and how could I try to resolve it with no other errors given in logs?


I think 100 may be the magic number. Are you using PhantomJScloud, their anonymous plan is limited to 100 PDFs (per day). If you create an account it’s increased to 500.

1 Like

Oh, that’s great news that there’s an easy way to wrap my head around this issue since it kept killing me for hours already. :grin: It’s actually funny how I guessed the number right, since I didn’t really count how many times did I generate the PDF. :joy:

Yes, I used their anonymous plan:

Ok, I will register and hopefully that will resolve my issue entirely. Big thanks for your swift response!

@hillel BTW, where the PDFs are generated? I tried to look in docs, but couldn’t find it. I checked the /tmp dir but no trace of PDFs there. In my .env there’s no PHANTOMJS_BIN_PATH.

What’s the recommended way to keep the framework/cache/data clean?

@david can you please help here?

1 Like


The PDFs are stored in the public/storage folder

each company has its own directory using the company_key column. and inside each company each client has their own folder with the client_hash as the folder name.

Thanks! What’s the recommended way to keep the framework/cache/data clean? Does Invoice Ninja automatically takes care of this?


you’ll want to chown the storage directory to the webuser - that should be all that is needed for this.

1 Like

All individual nested directories belong to the same user/group (their chown is the same as per the root dir of the app - the webuser) and the chmod is set as 755 per each directory of the following 4:
storage > framework > cache > data

I guess the automatic cleanup takes more time to trigger then. Ok, thank you for the tip.