docxtopdf2 1.0.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 ADDED
@@ -0,0 +1,12 @@
1
+ # docx-to-pdf
2
+
3
+ ## Requirements
4
+
5
+ - Node.js >= 18
6
+ - Microsoft Word (on Windows)
7
+
8
+ ## Installation
9
+
10
+ ```bash
11
+ npm install docxtopdf2
12
+ ```
Binary file
package/index.js ADDED
@@ -0,0 +1,3 @@
1
+ const { convertDocxToPdf } = require("./pdfService.js");
2
+
3
+ module.exports = { convertDocxToPdf };
package/package.json ADDED
@@ -0,0 +1,28 @@
1
+ {
2
+ "name": "docxtopdf2",
3
+ "version": "1.0.0",
4
+ "main": "index.js",
5
+ "files": [
6
+ "bin",
7
+ "index.js",
8
+ "pdfService.js"
9
+ ],
10
+ "scripts": {
11
+ "test": "echo \"Error: no test specified\" && exit 1"
12
+ },
13
+ "os": [
14
+ "win32"
15
+ ],
16
+ "keywords": [
17
+ "docx",
18
+ "pdf",
19
+ "converter"
20
+ ],
21
+ "author": "Indula Madhubhashana",
22
+ "license": "ISC",
23
+ "description": "Node package for convert docx to pdf.",
24
+ "repository": {
25
+ "type": "git",
26
+ "url": "https://github.com/indulagdm/node-docx-to-pdf.git"
27
+ }
28
+ }
package/pdfService.js ADDED
@@ -0,0 +1,46 @@
1
+ const { spawn } = require("child_process");
2
+ const path = require("path");
3
+ const { existsSync } = require("fs");
4
+
5
+ const getConvertorExe = () => {
6
+ const locatedAt = path.join(__dirname, "./", "bin", "win32", "DocxToPdf.exe");
7
+
8
+ if (existsSync(locatedAt)) {
9
+ console.log("Path founded.", locatedAt);
10
+ } else {
11
+ console.log("Not found.");
12
+ }
13
+
14
+ return locatedAt;
15
+ };
16
+
17
+ const convertDocxToPdf = (inputDocxPath) => {
18
+ return new Promise((resolve, reject) => {
19
+ const outputPdfPath = inputDocxPath.replace(".docx", ".pdf");
20
+
21
+ const python = spawn(getConvertorExe(), [inputDocxPath, outputPdfPath]);
22
+
23
+ let result = "";
24
+ let error = "";
25
+
26
+ python.stdout.on("data", (data) => {
27
+ result += data.toString();
28
+ });
29
+
30
+ python.stderr.on("data", (data) => {
31
+ error += data.toString();
32
+ });
33
+
34
+ python.on("close", (code) => {
35
+ if (code !== 0) {
36
+ reject(error);
37
+ } else {
38
+ resolve(result.trim());
39
+ }
40
+ });
41
+
42
+ return outputPdfPath;
43
+ });
44
+ };
45
+
46
+ module.exports = { convertDocxToPdf };