PhantomJS Problems/Questions (Cloud API key)

Hi there,

I’ve had zero luck getting a localized PhantomJS working after checking every suggestion I could find, it simply doesn’t work. I just get “Failed to load PDF document.” when testing in Chrome and in the laravel error logs the “Invalid response” as many others experience. If I try the phantomJS test script, it works but it won’t work from invoice ninja.

I’ve tried repository installs, manually installing and ensuring permissions are correct for phantomjs but it just simply doesn’t work despite everything I’ve tried.

I’m happy to use PhantomJS cloud but that doesn’t work either. I signed up for a phantomJS cloud and have an API key.

In the Invoice Ninja documentation, it says I need to modify this entry:
PHANTOMJS_CLOUD_KEY=‘a-demo-key-with-low-quota-per-ip-address’

My API key has hypens (eg. ak-xxxxx-xxxxx-xxxxx-xxxxx-xxxxx).

My questions are:

  1. Do the hyphens for the API key need to be there or not?

  2. Do the apostrophes need to be there at either ends of the API key for the PHANTOMJS_CLOUD_KEY entry?

I have tried just about everything and enabled “attach PDF” under email settings. There is simply no PDF attached to the emails, only an XML file (which I don’t actually want to be attached?)

I have also tried with and without a random entry in the .env file for PHANTOMJS_SECRET=.

Any ideas of what else I could try to get PhantomJS cloud working? I’m out of luck.

Dumb question, but when you tried the local install, did you delete or comment out the PHANTOMJS_CLOUD_KEY from your .env file, and did you add a line for PHANTOMJS_BIN_PATH?

Titanfail, yes I did. I never used PHANTOMJS_CLOUD_KEY and PHANTOMJS_BIN_PATH at the same time in the .env file.

Everytime I made a change I also restarted apache2 for good measure.

I’ve given up on the local install working, but I can’t even get the cloud working.

Do you have any insight to the formatting questions above you could assist with?

I think something might have changed in newer versions of PhantomJS Cloud, because I can’t get it working either. I have a local binary that works, so I just stick with that.

AFAIK, if the key they give you has hyphens, those stay in, and the singlequotes get dropped as they’re just enclosing the key to separate it from any other text surrounding it.

Out of curiosity, what was your path when you tried the local install?

Okay so I’ll consider PhantomJS cloud broken at the moment if it’s also not working for you.

I tried using /usr/local/bin/phantomjs and also /usr/bin/phantomjs. Of course moving the binary location accordingly.

I set the permissions to -775 each time and had played around trying different users, including root:root.

In my laravel error log I just got the “production.ERROR: PhantomJS – Invalid response”

I tried also editing my hosts file and changing the invoice ninja URL etc. but just got the same error regardless.

Which local binary version are you using and do you remember where you got it from?

I’m using the pre-built 2.1.1 binary from https://phantomjs.org/download.html and stuck it in /usr/bin/ with permissions set at 775 and the owner as root.

It shouldn’t make a difference, but I also did a quick apt purge phantomjs to get rid of the garbage repository version before trying to use the standalone binary.

I have similar problems. I CAN get the cloud option to work, but not the local binary option.

Tried everything.

And in my case I don’t even get error logs.


Are you using the dockerized option by any chance?

How is your API key formatted after PHANTOMJS_CLOUD_KEY=, bryanp?

I think it was PHANTOMJS_CLOUD_KEY: a-demo-key-with-low-quota-per-ip-address

Are you using docker?

Nah, not using docker.

Not sure why I can’t get either working. At this rate I think I’ll try getting it working tomorrow for the last time and if I can’t I’ll wait for invoice ninja V2 in order to use the PDF attachment feature!

Another thing to note is that using a local version of PhantomJS requires you to set PHANTOMJS_SECRET in the .env file. This can be pretty much any alphanumeric string you want.

When I comment out that line in my .env file, I get “Invalid Response” in the laravel error log as well. Uncomment the line, it’s back to working again.

Thanks for the suggestion however I mentioned this in my original post.

I tried with and without a random numeric value for PHANTOMJS_SECRET and it made no difference.

UPDATE! Got things working.

I’m using a raspberry Pi 2, so of course I need PhantomJS binaries that work with Raspberry pi 2.

I obtained this release for the pi architecture: https://github.com/fg2it/phantomjs-on-raspberry/releases/tag/v2.1.1-wheezy-jessie-armv6

Placed that into /usr/bin and did chmod 755.

I also ensured I had something entered for PHANTOMJS_SECRET in the .env file. I just entered random characters.

After doing that, it still didn’t work UNTIL I changed to a default template as mentioned on the configuration tips.

“If you’re using a custom design try using a standard one, if the PDF is outside the printable area it can fail.”

Now phantomjs generates normally and even attaches the PDF to emails if I choose.

So my first issue was I wasn’t using a phantomjs that could run on the raspberry PI and there seems to be something wrong with my custom template.

Might have to play around with my custom template to see if I can get it to work with PhantomJS. If anyone has pointers for that I’d appreciate the insight.