Errors While Generating a PDF

I have just installed Ninja v. 5.0.17 and just migrated all of my data from v.4.5.19.
I can not view any invoices. I even tried creating a new invoice to see if it had something to do with the migration, a new one would not work either.

I am receiving a 500 error.

When I setup the new installation, I did a test, and it did work. I did, however, have to put the following line in my .env file before installing (See other thread: Using Ninja on PHP 7.4)

PHANTOMJS_KEY=‘a-demo-key-with-low-quota-per-ip-address’

I noticed after the migration that was no longer in the .env file, so I added it back, in and that did generate a PDF, however, it is a PDF of the login screen, not of an invoice.

The /storage/logs/laravel.log file shows an error of:

production.ERROR: Trying to get property 'name' of non-object {"exception":"[object] (ErrorException(code: 0): Trying to get property 'name' of non-object at /data/www/live/ninja5/app/Jobs/Invoice/CreateInvoicePdf.php:90)

Thanks for any help you can provide.

David suggested the following in another thread:

In regards to the PDF, does your system have NPM/Node installed? The most common issue we see in regards to PDF generation is either permissions issues, or NPM/puppeteer not installed correctly on the system, we do have a section for this in the install guide here:

https://invoiceninja.github.io/selfhost.html#pdfs-not-generating-timeouts

The link provided uses apt-get. I’m using Amazon’s AMI2 Linux distro on AWS EC2, and it does not allow apt-get commands. I need to use yum to install. Most of the programs listed in the apt-get command are not available with the yum distros. I’m not sophisticated enough on Linux to know how to install things that are not in yum.

I do have the following two items installed.

nodejs.x86_64              1:6.17.1-1.el7               @epel
npm.x86_64                 1:3.10.10-1.6.17.1.1.el7     @epel

I tried putting in the NODE_PATH and NPM_PATH in the .env file, but that did not work.

I have changed the ownership of the entire ninja folder to be the webserver’s user, so I don’t think I shoudl be getting any permission errors. But I did try to check permissions, and I don’t see anything that looks odd. Is there a particular folder/file I should be looking at for permissions?

What else can I try?

The issue I’m getting the laravel.log doesn’t look like it has anything to do with the plugin, it is saying it is trying to get a property from a non-object:

[2020-10-03 19:44:38] production.ERROR: Trying to get property 'name' of non-object {"exception":"[object] (ErrorException(code: 0): Trying to get property 'name' of non-object at /data/www/live/ninja5/app/Jobs/Invoice/CreateInvoicePdf.php:90)

Thanks.

@cfullerbhope-org

[2020-10-03 19:44:38] production.ERROR: Trying to get property 'name' of non-object {"exception":"[object] (ErrorException(code: 0): Trying to get property 'name' of non-object at /data/www/live/ninja5/app/Jobs/Invoice/CreateInvoicePdf.php:90)

This is the issue. By chance, did you have any custom designs on your original installation? It appears it may be trying to reference a V4 design which doesn’t exist on V5.

Yes, I think I we had a custom design in the invoice design… So how do we go about working around this, can I somehow remove that?

Thanks!

I’ve been testing, and haven’t been able to get this fixed. Based on your last response, I went in and selected a default invoice template on the old installation. Redid the entire migration. Still getting the error.

I tried changing the Invoice Design to one of the generic types (i.e. Plain, Clean, etc.). but when I go back to generate the invoice, I still ge the “500: Internal Server Error” on the screen and in the laravel.log I see:

production.ERROR: Trying to get property 'name' of non-object {"exception":"[object] (ErrorException(code: 0): Trying to get property 'name' of non-object at /data/www/live/ninja5/app/Jobs/Invoice/CreateInvoicePdf.php:90)

During setup it removes the line from the .env file that I was asked to add to get around the test PDF not setting up during installation, if I add this line back into the .env file:

PHANTOMJS_KEY=‘a-demo-key-with-low-quota-per-ip-address’

I no longer get an error, but instead I get a PDF file of the log in screen.

I did some Google searches on how to test if NodeJS is installed correctly, and followed instructions I found there, and according to what I found, it is workng correctly.

Next steps?

@cfullerbhope-org sorry for the delay.

I think the issue may be that the invoice_design is hardcoded into the invoice column itself. so changing the default design may not actually do anything.

I’ll need to modify the migration to pick a default design if the custom one is not available. I’ll update here when i’ve implemented this.

If using phantomJS, then we do include a PDF of the login screen, so can confirm phantomjs is working for you!

I don’t understand your third comment. Yes, I get a PDF when I use phantomJS, but the PDF is not of an invoice, it is a PDF of the log in screen to log into Invoice Ninja.

At this point, I’ve spent WAY TO MUCH time on trying to get this to work and I’ve given up. I just spun up a separate small little AWS server to just run the old version with PHP 7.2 and won’t run this on my main server until version 5 is more complete.

I also had this problem with the PDF file. Appeared after installing the latest updates. The update most likely conflicted with our original invoice design. After setting the default settings, the project started working correctly.

We’ve change the test PDF to be less confusing in the latest commit.

Hi Timothy,
So you were also having the issue where PDFs generated showed your login screen?
What are “the default settings” you used to resolve this?
I’ve been going nuts trying to get PDF generation to work in my installation.

Thank you…
Jonathan

Hi cfullerbhope,
Did you ever figure out a solution for this? My fresh v5.0.25 installation seems to be doing the same thing you’ve described. I’ve detailed it here.
So far I’ve been unable to figure out how to resolve it, and I’ve not found any solutions on this forum forthcoming. Going a little nutty here. About to throw in the towel (spent way too many hours trying to deal with this).
Thanks so much… Jonathan

I’ve found the issue causing this (assuming you are using Phantom JS).

If you can pull in the latest changes from V5-Develop the issue should be resolved.

Please note there is a new .env variable

PHANTOMJS_PDF_GENERATION=true

Also, please ensure that the secret has a default value

PHANTOMJS_SECRET=secret

once done, just reload the cache

php artisan optimize

and retest

Thanks David.
I can now see the light of day! A PDF that actually shows something other than my login screen. Celebration!

The only remaining issue is the “Customize and Preview” can’t generate a preview. Results in 500 error. To keep discussion on this in one place, pls refer to my other thread, on which we’ve had some discussion. Thanks very much.