libreoffice-convert 1.3.1 → 1.3.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/Readme.md +24 -19
- package/index.js +3 -3
- package/package.json +3 -2
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2020 René Rössler
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/Readme.md
CHANGED
|
@@ -1,33 +1,38 @@
|
|
|
1
|
-
# libreoffice-convert
|
|
1
|
+
# libreoffice-convert
|
|
2
2
|
|
|
3
3
|
A simple and fast node.js module for converting office documents to different formats.
|
|
4
4
|
|
|
5
|
-
## Dependency
|
|
5
|
+
## Dependency
|
|
6
6
|
|
|
7
7
|
Please install libreoffice in /Applications (Mac), with your favorite package manager (Linux), or with the msi (Windows).
|
|
8
8
|
|
|
9
|
+
## Usage example
|
|
9
10
|
|
|
10
|
-
## Usage example ##
|
|
11
11
|
```javascript
|
|
12
|
-
|
|
12
|
+
'use strict';
|
|
13
13
|
|
|
14
14
|
const path = require('path');
|
|
15
|
-
const fs = require('fs');
|
|
16
|
-
|
|
17
|
-
const
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
const
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
15
|
+
const fs = require('fs').promises;
|
|
16
|
+
|
|
17
|
+
const libre = require('libreoffice-convert');
|
|
18
|
+
libre.convertAsync = require('util').promisify(libre.convert);
|
|
19
|
+
|
|
20
|
+
async function main() {
|
|
21
|
+
const ext = '.pdf'
|
|
22
|
+
const inputPath = path.join(__dirname, '/resources/example.docx');
|
|
23
|
+
const outputPath = path.join(__dirname, `/resources/example${ext}`);
|
|
24
|
+
|
|
25
|
+
// Read file
|
|
26
|
+
const docxBuf = await fs.readFile(inputPath);
|
|
27
|
+
|
|
28
|
+
// Convert it to pdf format with undefined filter (see Libreoffice docs about filter)
|
|
29
|
+
let pdfBuf = await libre.convertAsync(docxBuf, ext, undefined);
|
|
28
30
|
|
|
29
31
|
// Here in done you have pdf file which you can save or transfer in another stream
|
|
30
|
-
fs.
|
|
32
|
+
await fs.writeFile(outputPath, pdfBuf);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
main().catch(function (err) {
|
|
36
|
+
console.log(`Error converting file: ${err}`);
|
|
31
37
|
});
|
|
32
38
|
```
|
|
33
|
-
|
package/index.js
CHANGED
|
@@ -17,7 +17,7 @@ const convertWithOptions = (document, format, filter, options, callback) => {
|
|
|
17
17
|
switch (process.platform) {
|
|
18
18
|
case 'darwin': paths = ['/Applications/LibreOffice.app/Contents/MacOS/soffice'];
|
|
19
19
|
break;
|
|
20
|
-
case 'linux': paths = ['/usr/bin/libreoffice', '/usr/bin/soffice'];
|
|
20
|
+
case 'linux': paths = ['/usr/bin/libreoffice', '/usr/bin/soffice', '/snap/bin/libreoffice'];
|
|
21
21
|
break;
|
|
22
22
|
case 'win32': paths = [
|
|
23
23
|
path.join(process.env['PROGRAMFILES(X86)'], 'LIBREO~1/program/soffice.exe'),
|
|
@@ -37,7 +37,7 @@ const convertWithOptions = (document, format, filter, options, callback) => {
|
|
|
37
37
|
return callback(new Error('Could not find soffice binary'));
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
-
return callback(null,
|
|
40
|
+
return callback(null, res[0]);
|
|
41
41
|
}
|
|
42
42
|
);
|
|
43
43
|
},
|
|
@@ -55,7 +55,7 @@ const convertWithOptions = (document, format, filter, options, callback) => {
|
|
|
55
55
|
async.retry({
|
|
56
56
|
times: asyncOptions.times || 3,
|
|
57
57
|
interval: asyncOptions.interval || 200
|
|
58
|
-
}, (callback) => fs.readFile(path.join(tempDir.name, `source.${format}`), callback), callback)
|
|
58
|
+
}, (callback) => fs.readFile(path.join(tempDir.name, `source.${format.split(":")[0]}`), callback), callback)
|
|
59
59
|
]
|
|
60
60
|
}, (err, res) => {
|
|
61
61
|
tempDir.removeCallback();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "libreoffice-convert",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.5",
|
|
4
4
|
"description": "A simple and fast node.js module for converting office documents to different formats",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"repository": "https://github.com/elwerene/libreoffice-convert",
|
|
@@ -18,7 +18,8 @@
|
|
|
18
18
|
"contributors": [
|
|
19
19
|
"René Rössler <rene@freshx.de>",
|
|
20
20
|
"Dmitrii Kosinov <dnk@kakveselo.ru>",
|
|
21
|
-
"Brian Chong <bgorhoball@protonmail.com>"
|
|
21
|
+
"Brian Chong <bgorhoball@protonmail.com>",
|
|
22
|
+
"Võ Văn Khoa"
|
|
22
23
|
],
|
|
23
24
|
"license": "MIT",
|
|
24
25
|
"dependencies": {
|