Webshot pdf [Error: PhantomJS exited with return value 2]

hey guys,
I’m trying to create a pdf on the server from html with the following code

webshot('<html><body>solala</body></html>', 'test.pdf', {siteType: 'html'}, function(error) {
  if ( error ) return console.log( error );
  fs.readFile(filename, function(err, data) {
    if (err) return console.log(err);

which returns the following error [Error: PhantomJS exited with return value 2]. I have spend a day and a half trying to figure out what this error actually means (w/o luck so far).
versions, webshot: 0.16.0 but also tried 0.15.4 (tried both via meteorhacks:npm and the bryanmorgan:webshot package), phantom is installed locally from binaries (version 2.0) and on Modulus from dfischer:phantomjs package, which installs phantomjs: 1.9.9 I think. Locally, it works just fine, but on Modulus I always get the above errror.
Any help would be very much appreciated, thanks!

1 Like

Hi Tomsp, did you manage to get it working in the end?

I have been running into exactly the same problem,

-also tried both webshot: 0.15.4 and 0.16.0
-using dfischer:phantomjs
-keeps sending back [Error: PhantomJS exited with return value 2].

so far no succes in getting webshot working on modulus, while it works fine locally.

Any help would be very much appreciated indeed…

yes, i did, after a lot of trial and error (return value 2 :wink: ). i also wrote a short post about how i manage it in the end: https://medium.com/@tomsp/server-side-render-pdfs-with-blaze-and-phantomjs-in-meteor-34b8b63522c#.dd1xkquy3. let me know if that helps and you get it working.

Perfect, that was a very helpful post. Just making use of the phantomjs provided by modulus. I have got it running and am very happy with the results.

Thank you!

cool, glad I could help!

Hi, @tomsp!

I got the same error using webshot in Meteor on DigitalOcean Ubuntu 14.04:

webshot-error [Error: PhantomJS exited with return value 2]

The error is not being thrown on localhost.


hey @rudolfs did you read my blog post (scroll up a bit)? this is how i managed in the end.

Yes, @tomsp.

I looked at your post. Could be useful. :slight_smile:

Will try to implement directly with html and SSR package, without saving html file first. :slight_smile:

cool, let me know if you can get it to work. maybe post some code here or somewhere else. I am sure many people would appreciate it.

Hi, @tomsp!

Which package is this: var page = require('webpage').create();

it’s the webpage module from phantomjs, see here

I still had to implement your solution.

The only thing I changed - how the template is rendered - used SSR package.


SSR.compileTemplate(‘pdfLayout’, Assets.getText(‘pdf-layout.html’));

  getDocType: function() {
    return "<!DOCTYPE html>";

SSR.compileTemplate('pdfTemplate', Assets.getText('pdf-template.html'));

var data = {
  logo: Meteor.absoluteUrl('images/logo.jpg')

var html_string = SSR.render('pdfLayout', {
  css: css,
  template: 'pdfTemplate',
  data: data

well, I’m glad it works.

1 Like