Home Forums Support Local PhantomJS PDFs not attaching (PhantomJS Cloud works)

This topic contains 6 replies, has 2 voices, and was last updated by  jbakuwel 1 year, 2 months ago.

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
  • #17249



    Many thanks for making Invoice Ninja available to the community.

    I’ve installed Invoice Ninja v4.5.6 on a Debian Stretch server running Apache2 which sits behind a nginx proxy (also running Debian Stretch). Everything is working great, except invoice PDFs are not being attached to emails sent out. I have read the various reports on the forum, but have not yet been able to make it work. I feel I’m pretty close and would very much appreciate your help finding the issue.

    Invoices are attached successfully when I use PhantomJS Cloud, but I really hope I can avoid having to send my invoices through the cloud. Another reason, perhaps more important, is that access to the server is restricted and I would very much prefer to keep it that way instead of having to make it accessible to PhantomJSCloud and thus to the world.

    I’m using PhantomJS v2.1.1 installed from the Debian repositories. Relevant contents of .env are:


    From laravel-error.log:

    production.ERROR: PhantomJS – Invalid response https://<my.domain.com>/view/dkx8i3asloqichtckz7l9dntj6wck0nv?phantomjs=true&phantomjs_secret=verysecret: {“context”:”PHP”,”user_id”:1,”account_id”:1,”user_name”:”<company name>”,”method”:”PUT”,”user_agent”:”Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:63.0) Gecko/20100101 Firefox/63.0″,”locale”:”en”,”ip”:”<client-ip-address>”,”count”:9,”is_console”:”no”,”is_api”:”no”,”db_server”:”mysql”,”url”:”invoices/3″} []

    Running phantomjs test.pjs with the URL from the laravel-error log results in something that looks good, well.. I think it does. Note PDF encoded text removed.

    “body”: “”,
    “bodySize”: 185,
    “contentType”: “text/html”,
    “headers”: [
    “name”: “Server”,
    “value”: “nginx/1.10.3”
    “name”: “Date”,
    “value”: “Tue, 04 Dec 2018 05:06:10 GMT”
    “name”: “Content-Type”,
    “value”: “text/html”
    “name”: “Content-Length”,
    “value”: “185”
    “name”: “Connection”,
    “value”: “keep-alive”
    “name”: “Location”,
    “value”: “https://<my.domain.com>/view/dkx8i3asloqichtckz7l9dntj6wck0nv?phantomjs=true&phantomjs_secret=verysecret”
    “id”: 1,
    “redirectURL”: “https://<my.domain.com>/view/dkx8i3asloqichtckz7l9dntj6wck0nv?phantomjs=true&phantomjs_secret=verysecret”,
    “stage”: “start”,
    “status”: 301,
    “statusText”: “Moved Permanently”,
    “time”: “2018-12-04T05:06:10.334Z”,
    “url”: “http://<my.domain.com>/view/dkx8i3asloqichtckz7l9dntj6wck0nv?phantomjs=true&phantomjs_secret=verysecret”,
    “content”: “<head></head><body>data:application/pdf;base64,<base64-encloded-pdf-removed>body>”,
    “console”: []

    I’ve tried various entries in /etc/hosts (such as <local-ip-address>,, <public-ip-address>

    kind regards,



    What do you get when you run phantomjs -v? I ask because the last time I checked, the build in the Debian repositories was pretty much garbage, and would just throw off errors no matter what you asked of it.

    If it gives you anything but the version, I’d try uninstalling it with apt purge, then downloading the pre-compiled binary from http://phantomjs.org/download.html and sticking it in /usr/bin. Just be sure to have it marked as executable (755 usually does the trick).



    Hi Titanfail,

    Would it not be safe to conclude that, observing the output from test.pjs, that PhantomJS is working fine?
    Anyway, here you go.

    $ phantomjs -v
    QXcbConnection: Could not connect to display
    PhantomJS has crashed. Please read the bug reporting guide at
    <http://phantomjs.org/bug-reporting.html&gt; and file a bug report.
    $ QT_QPA_PLATFORM=minimal /usr/bin/phantomjs -v

    The above got me thinking though…

    After adding QT_QPA_PLATFORM=minimal to .env, it is now working! It hadn’t crossed my mind since PhantomJS supposedly (?) is a “headless” thing. But clearly it (or the Debian variant of it) by default attempts to use X…

    All working great now – thanks for your reply which put me on the right track!

    For the Ninja Invoices folks: perhaps the above can be added to





    Seems they’ve improved the repo build somewhat at least. The last time I tried to use it, even with a full desktop install of Debian, it crashed no matter what I did.

    Going forward, snagging the pre-compiled might be a better option if you want to save space, at least. It doesn’t install all the GTK dependencies which are just bloat on a server back-end.

    Happy to hear you got it working though!



    Hi Titanfail,

    I had a look at the dependencies of PhantomJS … looks OK to me, just a few libraries:


    Package: phantomjs
    Version: 2.1.1+dfsg-2
    Architecture: amd64
    Maintainer: Dmitry Smirnov <[email protected]>
    Installed-Size: 921
    Depends: libc6 (>= 2.15), libgcc1 (>= 1:3.0), libgl1-mesa-glx | libgl1, libqt5core5a (>= 5.6.0~beta), libqt5gui5 (>= 5.0.2), libqt5network5 (>= 5.3.0), libqt5printsupport5 (>= 5.2.0), libqt5webkit5 (>= 5.6.0~rc), libqt5widgets5 (>= 5.0.2), libstdc++6 (>= 4.4.0)
    Section: web
    Priority: extra
    Homepage: http://www.phantomjs.org/
    Description: minimalistic headless WebKit-based browser with JavaScript API
    PhantomJS is a headless WebKit with JavaScript API. It has fast and native
    support for various web standards: DOM handling, CSS selector, JSON, Canvas,
    and SVG.
    PhantomJS is an optimal solution for headless testing of web-based
    applications, site scraping, pages capture, SVG renderer, PDF converter
    and many other use cases.



    Those dependencies have dependencies, and then you end up with something like what it tells me on my Ubuntu system:

    The following NEW packages will be installed:
      at-spi2-core avahi-daemon bind9-host dconf-gsettings-backend dconf-service geoclue-2.0 glib-networking
      glib-networking-common glib-networking-services gsettings-desktop-schemas gstreamer1.0-plugins-base iio-sensor-proxy
      libatk-bridge2.0-0 libatspi2.0-0 libavahi-core7 libavahi-glib1 libbind9-160 libbrotli1 libcairo-gobject2
      libcdparanoia0 libcolord2 libdaemon0 libdconf1 libdns1100 libdouble-conversion1 libegl-mesa0 libegl1 libepoxy0
      libevdev2 libgbm1 libgeoclue-2-0 libgstreamer-plugins-base1.0-0 libgstreamer1.0-0 libgtk-3-0 libgtk-3-bin
      libgtk-3-common libgudev-1.0-0 libhyphen0 libice6 libinput-bin libinput10 libisc169 libisccc160 libisccfg160
      libjson-glib-1.0-0 libjson-glib-1.0-common liblwres160 libmbim-glib4 libmbim-proxy libmm-glib0 libmtdev1 libnss-mdns
      libogg0 libopus0 liborc-0.4-0 libproxy1v5 libqmi-glib5 libqmi-proxy libqt5core5a libqt5dbus5 libqt5gui5
      libqt5network5 libqt5positioning5 libqt5printsupport5 libqt5qml5 libqt5quick5 libqt5sensors5 libqt5svg5
      libqt5webchannel5 libqt5webkit5 libqt5widgets5 librest-0.7-0 libsm6 libsoup-gnome2.4-1 libsoup2.4-1 libtheora0
      libvisual-0.4-0 libvorbis0a libvorbisenc2 libwacom-bin libwacom-common libwacom2 libwayland-client0
      libwayland-cursor0 libwayland-egl1-mesa libwayland-server0 libwoff1 libxcb-icccm4 libxcb-image0 libxcb-keysyms1
      libxcb-randr0 libxcb-render-util0 libxcb-shape0 libxcb-util1 libxcb-xfixes0 libxcb-xinerama0 libxcb-xkb1
      libxkbcommon-x11-0 libxkbcommon0 libxtst6 modemmanager phantomjs qt5-gtk-platformtheme qttranslations5-l10n
      usb-modeswitch usb-modeswitch-data x11-common
    0 upgraded, 107 newly installed, 0 to remove and 1 not upgraded.
    Need to get 35.3 MB of archives.
    After this operation, 147 MB of additional disk space will be used.

    On a barebones Debian server, it shows this:

    The following NEW packages will be installed:
      gstreamer1.0-plugins-base libcdparanoia0 libdouble-conversion1 libdrm-amdgpu1 libdrm-intel1 libdrm-nouveau2
      libdrm-radeon1 libevdev2 libgl1-mesa-dri libgl1-mesa-glx libglapi-mesa libglew2.0 libglu1-mesa
      libgstreamer-plugins-base1.0-0 libgstreamer1.0-0 libgudev-1.0-0 libice6 libinput-bin libinput10 libllvm3.9 libmtdev1
      libogg0 libopus0 liborc-0.4-0 libpciaccess0 libpcre16-3 libqt5core5a libqt5dbus5 libqt5gui5 libqt5network5
      libqt5opengl5 libqt5printsupport5 libqt5qml5 libqt5quick5 libqt5sql5 libqt5sql5-sqlite libqt5svg5 libqt5webkit5
      libqt5widgets5 libsensors4 libsm6 libtheora0 libtxc-dxtn-s2tc libvisual-0.4-0 libvorbis0a libvorbisenc2 libwacom-bin
      libwacom-common libwacom2 libwebp6 libxcb-glx0 libxcb-icccm4 libxcb-image0 libxcb-keysyms1 libxcb-randr0
      libxcb-render-util0 libxcb-shape0 libxcb-util0 libxcb-xinerama0 libxcb-xkb1 libxkbcommon-x11-0 libxslt1.1
      libxxf86vm1 mesa-utils phantomjs qt5-gtk-platformtheme qttranslations5-l10n
    0 upgraded, 67 newly installed, 0 to remove and 0 not upgraded.
    Need to get 45.6 MB of archives.
    After this operation, 272 MB of additional disk space will be used.

    IMO, easier to just drop the 65mb prebuilt executable into /usr/bin/. Works just as well, less annoyance. =)



    Hi Titanfail,

    Yep, true.


Viewing 7 posts - 1 through 7 (of 7 total)

You must be logged in to reply to this topic.

Posted in: