-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
45 lines (42 loc) · 1.15 KB
/
index.js
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
var tmp = require("temporary");
var fs = require("fs");
var path = require("path");
var exec = require("child_process").exec;
var rimraf = require("rimraf");
module.exports = buffer => {
return new Promise(function(resolve, reject) {
var file = new tmp.File();
var outdir = new tmp.Dir();
console.log(file);
console.log(outdir);
file.writeFile(buffer, err => {
if (err) reject(err);
var cmd =
"soffice --headless --convert-to pdf " +
file.path +
" --outdir " +
outdir.path;
exec(cmd, function(error, stdout, stderr) {
if (error) {
reject(error);
} else {
fs.readFile(
path.join(
outdir.path,
path.basename(file.path, path.extname(path.basename(file.path))) +
".pdf"
),
(err, buffer) => {
if (err) reject(err);
rimraf(outdir.path, () => {
rimraf(file.path, () => {
resolve(buffer);
});
});
}
);
}
});
});
});
};