Reputation: 932
I'm generating a few html-based reports from my Meteor app. Everything works beautifully on my development machine, but when I push it up to the server, the pdf files that are returned are empty.
I've installed wkhtmltopdf 0.11 using the instructions in this post. I've also tried 0.9.9. When I go to print, I don't get any errors: just a pdf file without any content.
Any suggestions as to what I'm doing wrong would be appreciated!
Here's the code I'm using to generate the pdf:
Router.route('/reports/printHTML/:fileID?', {
name: 'reports.printHTML',
where: 'server',
action: function(){
var headers = {
'Content-type': 'application/pdf',
'Content-Disposition': "attachment; filename=space_report_" + this.params.fileID + ".pdf"
};
this.response.writeHead(200, headers);
var wk = Meteor.npmRequire('wkhtmltopdf');
var thisReport = PastReports.findOne({_id: this.params.fileID});
if(thisReport){
var html = thisReport.body + '<head><link rel="stylesheet" href="' + Meteor.absoluteUrl() + '/bootstrap.css"><link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap-theme.min.css"><link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/fullcalendar/2.2.6/fullcalendar.min.css"></head>';
var r = wk(html, {pageSize:'letter', orientation:'Landscape', zoom:1, B:"5mm", L:"5mm", R:"5mm", T:"5mm",}).pipe(this.response);
} else {
console.log("No report to print: " + this.params.fileID);
}
} });
Upvotes: 2
Views: 1641
Reputation: 79
I had a similar issue with PhantomJS. The bundle included my OSX binary of phantomjs instead of Ubuntu version. As Chip suggested, try to change the path accordingly to your OS distribuction.
Upvotes: 0
Reputation: 2192
The user running your meteor app should have wkhtmltopdf
in its PATH
, so you might want to try the following:
Login as the user running your meteor app and verify the PATH where wkhtmltopdf
is located with either which wkhtmltopdf
or whereis wkhtmltopdf
Login as the user running your meteor app and verify your PATH with echo $PATH
Set your PATH to contain the same path that is used by wkhtmltopdf
# inside ~/.bashrc or ~/.bash_profile
export PATH="$PATH:/usr/local/bin"
Alternatively, you can create a symbolic link to wkhtmltopdf
to an existing directory in your PATH. If wkhtmltopdf
is installed under /usr/local/bin
and you already have /usr/bin
in your PATH
:
ln -s /usr/local/bin/wkhtmltopdf /usr/bin/wkhtmltopdf
Also, be sure to check the browser's console or server logs for errors.
Upvotes: 2