Skip to content

Commit c700a7a

Browse files
committed
Added requirements.txt with the code
1 parent 4a8bf7b commit c700a7a

File tree

3 files changed

+80
-0
lines changed

3 files changed

+80
-0
lines changed

PDFToWord/README.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
## PDF to Word converter:
2+
3+
- This script converts a pdf file to a word document
4+
- Can be used if a pdf has to be edited
5+
6+
## Library used :
7+
- pdf2docx
8+
9+
## Steps to run the code:
10+
11+
If you have cloned this repository ,
12+
13+
```
14+
cd PDFtoWord
15+
pip install pdf2docx
16+
python main.py
17+
18+
```
19+
<hr/>
20+
21+
## Description :
22+
23+
1 . Takes the path of pdf from the user
24+
25+
2 . The user can add a custom name to the word doc otherwise the same name of the pdf will be used
26+
27+
3 . The word doc is created and stored in the same directory as that of the pdf
28+
29+
<hr/>
30+
31+
## Screenshot:
32+
[![ss.png](https://i.postimg.cc/RFjWQbbV/ss.png)](https://postimg.cc/wyQx9FpS)
33+
34+
[![1.png](https://i.postimg.cc/D0Bt3tk7/1.png)](https://postimg.cc/7JJBgtZR)
35+
[![2.png](https://i.postimg.cc/RhVDdX3y/2.png)](https://postimg.cc/jwmcd644)
36+
## Author :
37+
38+
[Divya Rao](https://github.com/dsrao711)
39+
40+

PDFToWord/main.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
from pdf2docx import Converter
2+
import os
3+
import sys
4+
5+
# Take PDF's path as input
6+
pdf = input("Enter the path to your file: ")
7+
assert os.path.exists(pdf), "File not found at, "+str(pdf)
8+
f = open(pdf,'r+')
9+
10+
#Ask for custom name for the word doc
11+
doc_name_choice = input("Do you want to give a custom name to your file ?(Y/N)")
12+
13+
if(doc_name_choice == 'Y' or doc_name_choice == 'y'):
14+
# User input
15+
doc_name = input("Enter the custom name : ")+".docx"
16+
17+
else:
18+
# Use the same name as pdf
19+
# Get the file name from the path provided by the user
20+
pdf_name = os.path.basename(pdf)
21+
# Get the name without the extension .pdf
22+
doc_name = os.path.splitext(pdf_name)[0] + ".docx"
23+
24+
25+
# Convert PDF to Word
26+
cv = Converter(pdf)
27+
28+
#Path to the directory
29+
path = os.path.dirname(pdf)
30+
31+
cv.convert(os.path.join(path, "", doc_name) , start=0, end=None)
32+
print("Word doc created!")
33+
cv.close()

PDFToWord/requirements.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
fire==0.4.0
2+
lxml==4.6.3
3+
pdf2docx==0.5.1
4+
PyMuPDF==1.18.12
5+
python-docx==0.8.10
6+
six==1.15.0
7+
termcolor==1.1.0

0 commit comments

Comments
 (0)