-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathpdfkitWrapper.js
More file actions
35 lines (31 loc) · 1.11 KB
/
pdfkitWrapper.js
File metadata and controls
35 lines (31 loc) · 1.11 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
PDFDocument = Npm.require('pdfkit');
PDFDocument.PX_PER_CM = 28.33;
fs = Npm.require('fs');
fs.writeFileFiber = Meteor.wrapAsync(fs.writeFile.bind(fs));
// New output methode with a callBack respecting the classic params (err, result)
PDFDocument.prototype.outputForMeteor = function(fn) {
return this.finalize((function(_this) {
return function() {
var out;
out = [];
_this.generateHeader(out);
return _this.generateBody(out, function() {
var k, ret, _i, _len;
_this.generateXRef(out);
_this.generateTrailer(out);
ret = [];
for (_i = 0, _len = out.length; _i < _len; _i++) {
k = out[_i];
ret.push(k + '\n');
}
// add "null ," to get a classic callBack prototype !
return fn(null, new Buffer(ret.join(''), 'binary'));
});
};
})(this));
};
/**
* Sync but non blocking thread (Fibered)
*/
PDFDocument.prototype.outputSync = Meteor.wrapAsync(PDFDocument.prototype.outputForMeteor);
PDFDocument.prototype.writeSync = function (filename) {return fs.writeFileFiber(filename, this.outputSync(), 'binary');}