libreoffice-convert 1.3.4 → 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/Readme.md +24 -19
- package/package.json +1 -1
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/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",
|