-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathmethods.js
More file actions
65 lines (53 loc) · 1.46 KB
/
Copy pathmethods.js
File metadata and controls
65 lines (53 loc) · 1.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import webshot from 'webshot';
import fs from 'fs';
import Future from 'fibers/future';
Meteor.methods({
'pokemon/generate_pdf': function() {
// SETUP
// Grab required packages
var fut = new Future();
var fileName = "pokemon-report.pdf";
// GENERATE HTML STRING
var css = Assets.getText('style.css');
SSR.compileTemplate('layout', Assets.getText('layout.html'));
Template.layout.helpers({
getDocType: function() {
return "<!DOCTYPE html>";
}
});
SSR.compileTemplate('pokemon_report', Assets.getText('pokemon-report.html'));
// PREPARE DATA
var pokemon = Pokemon.find({});
var data = {
pokemon: pokemon
}
var html_string = SSR.render('layout', {
css: css,
template: "pokemon_report",
data: data
});
// WEBSHOT OPTIONS
var options = {
"paperSize": {
"format": "Letter",
"orientation": "portrait",
"margin": "1cm"
},
siteType: 'html'
};
// COMMENCE WEBSHOT
console.log("Commencing webshot...");
webshot(html_string, fileName, options, function(err) {
fs.readFile(fileName, function (err, data) {
if (err) {
return console.log(err);
}
fs.unlinkSync(fileName);
fut.return(data);
});
});
let pdfData = fut.wait();
let base64String = new Buffer(pdfData).toString('base64');
return base64String;
}
});