-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
36 lines (28 loc) · 1.05 KB
/
index.js
File metadata and controls
36 lines (28 loc) · 1.05 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
const libre = require('libreoffice-convert');
const download = require('download');
const path = require('path');
const fs = require('fs');
(async () => {
if(!process.argv[2] || !process.argv[3] ) {
console.log('Please provide the fileUrl and fileName');
return;
}
const fileUrl = process.argv[2];
const fileName = process.argv[3];
const outputName = process.argv[4] ? process.argv[4] : 'output';
const filePath = `dist/${fileName}`
await download(fileUrl, 'dist', { filename: fileName });
const extend = '.pdf'
const enterPath = path.join(__dirname, filePath);
const outputPath = path.join(__dirname, `/${outputName}${extend}`);
// Read file
file = fs.readFileSync(enterPath);
// Convert it to pdf format with undefined filter (see Libreoffice doc about filter)
libre.convert(file, extend, undefined, (err, done) => {
if (err) {
console.log(`Error converting file: ${err}`);
}
// Here in done you have pdf file which you can save or transfer in another stream
fs.writeFileSync(outputPath, done);
});
})()