Skip to content

Commit 635e9b2

Browse files
includ dir conversion in docs
1 parent 148fafb commit 635e9b2

1 file changed

Lines changed: 36 additions & 1 deletion

File tree

README.md

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Docx to PDF Converter
22

3-
A simple and lightweight npm package for converting Word documents (docx) to PDF format using Node.js.
3+
A lightweight npm package designed to convert Word documents (docx) to PDF format. While similar tools exist in Python, I found a gap in the JavaScript ecosystem and decided to fill it by creating this simple and efficient solution.
44

55
## Features
66

@@ -18,6 +18,8 @@ npm i docx2pdf-converter
1818

1919
## Usage
2020

21+
This line of code simply converts single docx file into pdf file
22+
2123
```javascript
2224
const topdf = require('docx2pdf-converter')
2325

@@ -26,4 +28,37 @@ const inputPath = './report.docx';
2628
topdf.convert(inputPath,'output.pdf')
2729
```
2830

31+
## converting entire directory of docs file into pdf file
32+
33+
This line of code converts entire directory of docx file into another directory of pdf file
34+
35+
```javascript
36+
const fs = require('fs');
37+
const path = require('path');
38+
const { convert, resolvePaths } = require('docx2pdf-converter');
39+
40+
41+
function convertDirectory(inputDir, outputDir) {
42+
const files = fs.readdirSync(inputDir);
43+
44+
files.forEach((file) => {
45+
if (file.endsWith('.docx')) {
46+
const inputPath = path.join(inputDir, file);
47+
const { output } = resolvePaths(inputPath, outputDir);
48+
convert(inputPath, output);
49+
console.log(`Converted: ${file}`);
50+
}
51+
});
52+
}
53+
/*
54+
assume the both directories input and output are in same folder
55+
if they dont exist the you can give absolute path to that folder
56+
*/
57+
const inputDirectory = './inputdir';
58+
const outputDirectory = './outputdir';
59+
60+
convertDirectory(inputDirectory, outputDirectory);
61+
```
62+
63+
2964

0 commit comments

Comments
 (0)