docxtopdf2 1.1.0
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 +9 -0
- package/bin/win32/pdf_convertor.exe +0 -0
- package/package.json +23 -0
- package/src/index.js +1 -0
- package/src/runner.js +56 -0
package/README.md
ADDED
|
Binary file
|
package/package.json
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "docxtopdf2",
|
|
3
|
+
"version": "1.1.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"main": "src/index.js",
|
|
6
|
+
"files": [
|
|
7
|
+
"src",
|
|
8
|
+
"bin"
|
|
9
|
+
],
|
|
10
|
+
"os": [
|
|
11
|
+
"win32"
|
|
12
|
+
],
|
|
13
|
+
"scripts": {
|
|
14
|
+
"test": "node src/index.js"
|
|
15
|
+
},
|
|
16
|
+
"keywords": [],
|
|
17
|
+
"author": "Indula Madhubhashana",
|
|
18
|
+
"license": "ISC",
|
|
19
|
+
"description": "",
|
|
20
|
+
"engines": {
|
|
21
|
+
"node": ">=22"
|
|
22
|
+
}
|
|
23
|
+
}
|
package/src/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { convertDocxToPdf } from "./runner.js";
|
package/src/runner.js
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { spawn } from "child_process";
|
|
2
|
+
import { join } from "path";
|
|
3
|
+
import { fileURLToPath } from "url";
|
|
4
|
+
|
|
5
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
6
|
+
const __dirname = path.dirname(__filename);
|
|
7
|
+
|
|
8
|
+
function getBinary() {
|
|
9
|
+
switch (process.platform) {
|
|
10
|
+
case "win32":
|
|
11
|
+
return path.join(__dirname, "../bin/win32/processor.exe");
|
|
12
|
+
case "linux":
|
|
13
|
+
return path.join(__dirname, "../bin/linux/processor");
|
|
14
|
+
case "darwin":
|
|
15
|
+
return path.join(__dirname, "../bin/darwin/processor");
|
|
16
|
+
default:
|
|
17
|
+
throw new Error("Unsupported OS");
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
// function getPdfConvertorPath() {
|
|
22
|
+
// return join(__dirname, "../", "bin", "pdf_convertor.exe");
|
|
23
|
+
// }
|
|
24
|
+
|
|
25
|
+
function convertDocxToPdf(inputDocxPath) {
|
|
26
|
+
return new Promise((resolve, reject) => {
|
|
27
|
+
const bin = getBinary();
|
|
28
|
+
|
|
29
|
+
const outputPdfPath = inputDocxPath.replace(".docx", ".pdf");
|
|
30
|
+
|
|
31
|
+
const python = spawn(bin[(inputDocxPath, outputPdfPath)]);
|
|
32
|
+
|
|
33
|
+
let result = "";
|
|
34
|
+
let error = "";
|
|
35
|
+
|
|
36
|
+
python.stdout.on("data", (data) => {
|
|
37
|
+
result += data.toString();
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
python.stderr.on("data", (data) => {
|
|
41
|
+
error += data.toString();
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
python.on("close", (code) => {
|
|
45
|
+
if (code !== 0) {
|
|
46
|
+
reject(error);
|
|
47
|
+
} else {
|
|
48
|
+
resolve(result.trim());
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
return outputPdfPath;
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export { convertDocxToPdf };
|