I created a very small app which have to render a dynamic blaze template into a PDF.
I used wkhtmltopdf with SSR to achieve the result. This is the code:
'render.pdf': function(menu){
var fs = Npm.require('fs');
var fsPath = require('fs-path');
console.log('######################################### from server method 1 [BEGIN]');
var html = SSR.render("menuPrivate");
console.log('######################################### from server method 2 [RENDER HTML ON SERVER]');
var pdfStream = wkhtmltopdf(html);
function categories(){
return Category.find({}, {sort: {categoryOrder: 1}});
}
console.log('######################################### from server method 3 [START wkhtmltopdf]');
wkhtmltopdf(html, function(code, signal) {
console.log('######################################### from server method 4 [INSIDE wkhtmltopdf]');
console.log('worked!');
var content= fs.readFileSync('out.pdf');
fsPath.writeFile('../../../../../public/out.pdf', content, function(err){
if(err) {
throw err;
} else {
console.log('**************** File created ****************');
console.log('')
}
});
console.log('######################################### from server method 5 [BEFORE CREATING OUTPUT FILE]');
}).pipe(fs.createWriteStream('out.pdf'));
console.log('######################################### from server method 6 [FINISH - PDF CREATED]');
},
Now the problem I have is that it only works on my computer, once I run it on another computer it doesn’t work. Do you have any idea of the reason?