tomsp
October 30, 2015, 3:44pm
1
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);
console.log(data);
});
});
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
tboon
November 20, 2015, 3:28am
2
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…
tomsp
November 20, 2015, 8:18am
3
yes, i did, after a lot of trial and error (return value 2 ). 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.
tboon
November 24, 2015, 3:40am
4
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!
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.
Thanks.
tomsp
February 3, 2016, 6:48pm
7
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.
Will try to implement directly with html and SSR package, without saving html file first.
tomsp
February 3, 2016, 7:56pm
9
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.
rudolfs
February 4, 2016, 10:23am
10
Hi, @tomsp !
Which package is this: var page = require('webpage').create();
tomsp
February 4, 2016, 11:41am
11
it’s the webpage
module from phantomjs
, see here
rudolfs
February 4, 2016, 5:58pm
12
I still had to implement your solution.
The only thing I changed - how the template is rendered - used SSR package.
Example:
SSR.compileTemplate(‘pdfLayout’, Assets.getText(‘pdf-layout.html’));
Template.pdfLayout.helpers({
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
});