diff --git a/Word to PDF/README.md b/Word to PDF/README.md new file mode 100644 index 00000000..cbd66501 --- /dev/null +++ b/Word to PDF/README.md @@ -0,0 +1,44 @@ +# Word to PDF Converter + +A simple yet powerful Python script to convert Microsoft Word `.docx` files into PDF documents with just a few clicks. + +--- + +## 🎯 Key Features + +- **User-Friendly Interface:** Uses a graphical file dialog to easily select your Word file. + +- **Effortless Conversion:** Converts your `.docx` file to a `.pdf` in the same directory, using the same filename. + +- **Cross-Platform:** Built on the robust docx2pdf library, which works seamlessly on Windows, macOS, and Linux. + +--- + +## ⚙️ Setup Instructions + +### 1️⃣ Clone the repository: + ```bash + git clone https://github.com/ndleah/python-mini-project.git + cd Word to PDF + ``` + +### 2️⃣ Install Dependencies + +```bash +pip install -r requirements.txt +``` + +### 3️⃣ Run the Program: + +```bash +python main.py +``` + +--- + + +## 🤖 Author + +[SrujanPR](https://github.com/SrujanPR) + +--- diff --git a/Word to PDF/main.py b/Word to PDF/main.py new file mode 100644 index 00000000..9c47e1f3 --- /dev/null +++ b/Word to PDF/main.py @@ -0,0 +1,34 @@ +from docx2pdf import convert +from tkinter import Tk, filedialog + +def convert_docx_to_pdf(): + # Initialize and hide the main tkinter window + root = Tk() + root.withdraw() + + # Open a file dialog to let the user select a .docx file + docx_file_path = filedialog.askopenfilename( + title="Select a Word file (.docx)", + filetypes=[("Word Documents", "*.docx")] + ) + + # If no file is selected, print a message and exit + if not docx_file_path: + print("No file selected. Exiting.") + return + + # Create the output file path by replacing the extension + pdf_file_path = docx_file_path.replace(".docx", ".pdf") + + print(f"Converting '{docx_file_path}' to PDF...") + try: + # Convert the .docx file to a PDF + convert(docx_file_path, pdf_file_path) + print(f"Conversion successful! PDF saved to: '{pdf_file_path}'") + except Exception as e: + # Handle any errors during the conversion process + print(f"An error occurred during conversion: {e}") + +# Run the conversion function when the script is executed +if __name__ == "__main__": + convert_docx_to_pdf() diff --git a/Word to PDF/requirements.txt b/Word to PDF/requirements.txt new file mode 100644 index 00000000..a42b1cec --- /dev/null +++ b/Word to PDF/requirements.txt @@ -0,0 +1,2 @@ +docx2pdf +tkinter \ No newline at end of file