PhantomJS - Unable to decode

Can you check that PHANTOMJS_SECRET is set to a random value in the .env file

Yes i set it to

PHANTOMJS_BIN_PATH=/usr/bin/phantomjs
PHANTOMJS_SECRET=asdf343562qxd

You may want to try running the PhantomJS script from the command line.

http://docs.invoiceninja.com/en/latest/configure.html#phantomjs

I executed the script and this is the result and many cryptic Code after that:

\n{
“body”: “”,
“bodySize”: 87327,
“contentType”: “text/html; charset=UTF-8”,
“headers”: [
{
“name”: “Server”,
“value”: “nginx”
},
{
“name”: “Content-Type”,
“value”: “text/html; charset=UTF-8”
},
{
“name”: “Transfer-Encoding”,
“value”: “chunked”
},
{
“name”: “Connection”,
“value”: “keep-alive”
},
{
“name”: “Vary”,
“value”: “Accept-Encoding”
},
{
“name”: “X-Powered-By”,
“value”: “PHP/5.6.30-0+deb8u1”
},
{
“name”: “Cache-Control”,
“value”: “no-cache”
},
{
“name”: “Date”,
“value”: “Sun, 30 Jul 2017 18:42:44 GMT”
},
{
“name”: “Set-Cookie”,
“value”: “XSRF-TOKEN=eyJpdiI6ImlUSU9RUnhjK3RLY0tqRTdjNDB2SXc9PSIsInZhbHVlIjoiYldUaW5BYmlmS2xmbTZaRGRITFwvOERpYkluUWZQS3pVNkF2VFZHNzFGMWgxemNTZGxSYStpVEs0WVFGbUhsT09KeXJ4TG4xYjdITEhZa3ZuS2wyanhRPT0iLCJtYWMiOiI2NjYyZjhhNDgyNmQ4ZWM0ZGU4Y2ExODI0YjY2MzQ2OTQ0NTdlYWUxOTg3MGU0MmEyNDE2YTM5NmI3MzkwYzFhIn0%3D; expires=Mon, 31-Jul-2017 02:42:44 GMT; Max-Age=28800; path=/\nninja_session=eyJpdiI6IkY1TVwvUWlra2ZQYUNoT3BQVlBPVWJRPT0iLCJ2YWx1ZSI6IndkaFc4Z05RZnJVbHdxTlByOXF1cU0ybkJxZDhZRkdNemdTYjlCaTZCdzNEN1NpZTFWaElVdXQ5RTBLUFdyQjRGTkVtbUlkeXlzY0F2UzIrWmI0NTd3PT0iLCJtYWMiOiJjODA2YWE1ZjUzODYyYjUwZjI5MzNhZjQ2NDg1MTk3NDliYmMwZWUyYTc4MzhiMWZkMjBhMTMyZjk3NWNlMjdlIn0%3D; expires=Mon, 31-Jul-2017 02:42:44 GMT; Max-Age=28800; path=/; httponly”
},
{
“name”: “Strict-Transport-Security”,
“value”: “max-age=63072000; includeSubdomains; preload” },
{
“name”: “Content-Encoding”,
“value”: “gzip”
}
],
“id”: 1,
“redirectURL”: null,
“stage”: “start”,
“status”: 200,
“statusText”: “OK”,
“time”: “2017-07-30T18:42:44.231Z”,
“url”: “https://server1/ninja/public/view/roay3ruvqeop84qwktpsuyajthssh7uk”,
“content”: "<head>\n <!-- Source: https://github.com/invoiceninja/invoiceninja -->\n <!-- Version: 3.5.1 -->\n <meta charset=“utf-8”>\n\n <title>Invoice Ninja

Make sure you’re testing with the full link from the logs, it should include phantomjs=true

I tested with the full link and this is the result:

´{
“body”: “”,
“bodySize”: 65230,
“contentType”: “text/html; charset=UTF-8”,
“headers”: [
{
“name”: “Server”,
“value”: “nginx”
},
{
“name”: “Content-Type”,
“value”: “text/html; charset=UTF-8”
},
{
“name”: “Transfer-Encoding”,
“value”: “chunked”
},
{
“name”: “Connection”,
“value”: “keep-alive”
},
{
“name”: “Vary”,
“value”: “Accept-Encoding”
},
{
“name”: “X-Powered-By”,
“value”: “PHP/5.6.30-0+deb8u1”
},
{
“name”: “Cache-Control”,
“value”: “no-cache”
},
{
“name”: “Date”,
“value”: “Mon, 31 Jul 2017 04:40:28 GMT”
},
{
“name”: “Set-Cookie”,
“value”: “XSRF-TOKEN=eyJpdiI6Ilc4SnhSTVFCOFdraDBnXC9VbHZWUkF3PT0iLCJ2YWx1ZSI6IkFMZWRDa3hrYUVZK3NyWEdBXC9QMW1kMFVcL2Y3R0JKRUR3cXl2dDMwZnpZSEV2TE9oZ09BRUpQYkNaZWw2MWlcLzZ1Q2FW
Tm5ramtmXC92Q05sT0tQdGlSQT09IiwibWFjIjoiODI2OGQ0ZDRiYmNlZjNkZGQyZmQzMjVjYTY2MGFmNDUxZjFhMWZiOWY4NjMzNzU5MmJjMDQxMWNkZDAxODk5YSJ9; expires=Mon, 31-Jul-2017 12:40:28 GMT; Max-Age=28800; p
ath=/\nninja_session=eyJpdiI6IkhUaXUrQ09LSjZUaGI1dUV5SXZ5dWc9PSIsInZhbHVlIjoicjJzbFFFbGt3algwcGNSNzlGZjY4S2RlTjJzZlFJbXFnT1JUMDlhM0RnT3hlXC9QdWhMWEt2V2NDR1lFV0ZVZ2orMUxrZXdiaUJlbFY0b2h1
VlRRZUxRPT0iLCJtYWMiOiJiNTVmZDMyZWM4ZGUyZWI4MmMwNzM2MmZjNjg2NTFiNjllMTRmODA2NDFjMTdiOTRiMDA2MWY3OGFjYTc4ZjczIn0%3D; expires=Mon, 31-Jul-2017 12:40:28 GMT; Max-Age=28800; path=/; httponl
y”
},
{
“name”: “Strict-Transport-Security”,
“value”: “max-age=63072000; includeSubdomains; preload”
},
},
{
“name”: “Content-Encoding”,
“value”: “gzip”
}
],
“id”: 1,
“redirectURL”: null,
“stage”: “start”,
“status”: 200,
“statusText”: “OK”,
“time”: “2017-07-31T04:40:28.898Z”,
“url”: “https://server1/ninja/public/view/roay3ruvqeop84qwktpsuyajthssh7uk?phantomjs=true&phantomjs_secret=asdf343562qxd”,
“content”: "<head></head><body>data:application/pdf;base64,JVBERi0xLjMKJf////8KNyAwIG9iago8PAovVHlwZSAvRXh0R1N0YXRlCi9jYSAxCj4+CmVuZG9iago4IDAgb2JqCjw8Ci9UeXBlIC9F…
“console”: []
}`

I’m not sure, that looks correct.

What is different with debug=true? With this setting it is working.

This was reported by another user in the past but the latest code has a fix for the issue.

https://www.invoiceninja.com/forums/topic/local-phantomjs-pdf-generation/#post-6068

Unfortunately i found this thread and as a test i increased the timeout but this didn’t change something.

Ok after another day of try and error i found the solution:

I customized the business template and during this i set the outer margin of the template to:

[
  40,
  40,
  40,
  120
]

and the footer to:


{
  "columns": [
    {
      "layout": "noBorders",
      "table": {
        "headerRows": 1,
        "widths": [
          "auto"
        ],
        "body": [
          [
            {
              "text": "Bankverbindung",
              "bold": true,
              "fontSize": 12
            }
          ],
          [
            {
              "text": "Kontoinhaber: Dummy Dummy\nIBAN: DE00 0000 0000 0000 0000 00\nBIC: XXXXXXXXXX\nKreditinstitut: Bank of Gnu",
              "bold": false,
              "fontSize": 10
            }
          ]
        ]
      }
    }
  ],
  "margin": [
    40,
    40,
    40,
    0
  ]
}

The problem was the margin on the footer. I found out that i seems to be outside of the “printable” area of the invoice and phantomjs seems to fail with the generation on Invoiceninja 3.5.0 and 3.5.1. After i changed the margin of the footer to:

  "margin": [
    40,
    0,
    40,
    0
  ]

the pdf got attached to the mail.

There was another interesting error. If the price is not set to 0 in the invoice items and the amount is 0 then no pdf is attached to the mail too. Otherwise the pdf is created.

Glad you were able to figure it out, thanks for sharing the solution!