Using local phantomjs binary for pdf generation

I am running the application on a local machine using artisan serve and getting in to pdf creation error. What I know is that I can’t use PhantomJS Cloud because the running application isn’t available via public domain. So my question is how can a local install of phantomjs can be configured to generate pdf previews etc.

I have following phantomjs settings in .env file:

PHANTOMJS_PDF_GENERATION=true
PHANTOMJS_SECRET=secret
PHANTOMJS_BIN_PATH=/usr/local/bin/phantomjs

Going through the code files, what I figured out so far is whenever PHANTOMJS_PDF_GENERATION is true the pdf generation goes to the web service of PhantomJS and not to local bin. What else do I need to configure to use the bin and not the web serice

Thanks

phantomjs locally is not supported.

we do have a new PDF generation engine which you may want to consider, you just need to add the following variables to your .env (be sure to run php artisan optimize afterwards)

EXPERIMENTAL_PDF_ENGINE=true
EXPERIMENTAL_PDF_ENGINE_CHROMIUM_PATH=/usr/bin/google-chrome

I used the above variables but now I am getting following error:

Class 'App\Utils\Traits\Pdf\ChromiumPdf' not found

This is a bug, if you can pull in the latest changes from v5-develop it will be fixed in there.

1 Like

@david is this implemented in the latest docker image?

phantomjs locally is not supported.
we do have a new PDF generation engine which you may want to consider, you just need to add the following variables to your .env (be sure to run php artisan optimize afterwards)

EXPERIMENTAL_PDF_ENGINE=true
EXPERIMENTAL_PDF_ENGINE_CHROMIUM_PATH=/usr/bin/google-chrome

Yes!

You can put that in the .env file of Invoice Ninja or in docker-compose under envinronment variables (app section).

With next Docker image update it will enabled by default for you :+1:

Awesome, I’ll give it a go, thank you

We need to build and test the new image. I’ll add this to my backlog.

Hey @kamikaks,

We’ve pushed new update thru Docker and new one uses previously experimental PDF engine. Can you please update & give it a try?

Thanks!

I did a fresh install and got the latest code from the v5-develop branch. While installing, it showed me a pdf being generated when I pressed the Test pdf button. But after installation, when I went to the invoice design section to customize and preview, it shows me a 500: Internal Server Error and exception window shows: Browser binary not found. Make sure you download it or set using setChromiumPath().
I double checked my google-chrome path, which is correct. Any idea why this exception is occurring?

hi jsan,

can you try running vendor/bin/snappdf download

@ben Sure will try it now. Is it now the default PDF generator then? Or should I use the environmental variables

EXPERIMENTAL_PDF_ENGINE=true
EXPERIMENTAL_PDF_ENGINE_CHROMIUM_PATH=/usr/bin/google-chrome

hi david,
now I am getting a time out exception:

production.ERROR: The process "/home/jsan/projects/invoiceninja/vendor/beganovich/snappdf/versions/chrome --headless --disable-gpu --print-to-pdf="/tmp/pdf_47MpnU.pdf" --print-to-pdf-no-header --hide-scrollbars --no-margins --no-sandbox /tmp/html_2ihmgW.html" exceeded the timeout of 60 seconds. {"userId":1,"exception":"[object] (Symfony\\Component\\Process\\Exception\\ProcessTimedOutException(code: 0): The process \"/home/jsan/projects/invoiceninja/vendor/beganovich/snappdf/versions/chrome --headless --disable-gpu --print-to-pdf=\"/tmp/pdf_47MpnU.pdf\" --print-to-pdf-no-header --hide-scrollbars --no-margins --no-sandbox /tmp/html_2ihmgW.html\" exceeded the timeout of 60 seconds. at /home/jsan/projects/invoiceninja/vendor/symfony/process/Process.php:1203)

@ben thoughts?

@jsan does it consistently fail?

@david yeah, it keeps crashing with the same exception which I mentioned in my previous reply