Skip to content

Commit fdc27a9

Browse files
authored
Merge pull request #181 from aashitagrawal/master
Document Conversion: Word to PDF
2 parents f8af0b5 + 5344188 commit fdc27a9

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ More information on contributing and the general code of conduct for discussion
107107
| Website Blocker | [Website Blocker](https://github.com/DhanushNehru/Python-Scripts/tree/master/Website%20Blocker) | Downloads the website and loads it on your homepage in your local IP. |
108108
| Website Cloner | [Website Cloner](https://github.com/DhanushNehru/Python-Scripts/tree/master/Website%20Cloner) | Clones any website and opens the site in your local IP. |
109109
| Weight Coverter | [Weight Converter](https://github.com/WatashiwaSid/Python-Scripts/tree/master/Weight%20Converter) | Simple GUI script to convert weight in different measurement units. |
110+
| Word to PDF | [Word to PDF](https://github.com/DhanushNehru/Python-Scripts/tree/master/Word%20to%20PDF%20converter) | A Python script to convert a MS Word file to a PDF file. |
110111
| Wikipedia Data Extractor | [Wikipedia Data Extractor](https://github.com/DhanushNehru/Python-Scripts/tree/master/Wikipedia%20Data%20Extractor) | A simple Wikipedia data extractor script to get output in your IDE. |
111112
| Youtube Downloader | [Youtube Downloader](https://github.com/DhanushNehru/Python-Scripts/tree/master/Youtube%20Downloader) | Download any video from [YouTube](https://youtube.com) in video or audio format! |
112113

Word to PDF converter/wordToPDF.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import os
2+
from docx2pdf import convert
3+
4+
def convert_word_to_pdf(word_file_path):
5+
try:
6+
output_pdf_path = os.path.splitext(word_file_path)[0] + ".pdf"
7+
convert(word_file_path, output_pdf_path)
8+
print("Conversion successful. PDF saved")
9+
except Exception as e:
10+
print(f"Error occurred during conversion: {e}")
11+
12+
if __name__ == "__main__":
13+
# Replace the paths below with the actual paths of your Word files
14+
word_files = [
15+
r"enter word file location path 1",
16+
r"enter word file location path 2",
17+
r"enter word file location path 3",
18+
r"enter word file location path 4",
19+
r"enter word file location path 5",
20+
r"enter word file location path 6",
21+
r"enter word file location path 7",
22+
r"enter word file location path 8",
23+
r"enter word file location path 9",
24+
# you can add as many as you want
25+
]
26+
27+
for word_file_path in word_files:
28+
convert_word_to_pdf(word_file_path)

0 commit comments

Comments
 (0)