This Python script automates the conversion of Word documents to PDFs in a specified folder using the docx2pdf
library.
-
Clone this repository or download the script.
-
(Optional) Please use a Virtual Environment in Python:
python -m venv .venv .venv\Scripts\activate # Activate the virtual environment (Windows)
-
Install the required Python library using pip:
pip install docx2pdf
-
Ensure you have Microsoft Word installed on your system. This script relies on the
docx2pdf
library for document conversion, which in turn uses Microsoft Word.
-
Open the command prompt or terminal.
-
Navigate to the directory where the script is located.
-
Run the script using the following command:
python word_to_pdf.py
-
The script will prompt you for the input folder containing Word documents and the output folder where the PDFs will be saved. Provide the paths as instructed.
-
The script will convert all Word documents (
.docx
and.doc
) in the input folder to PDFs and save them in the output folder. -
The converted PDFs will be named the same as the original Word documents.
-
You can now find the converted PDFs in the specified output folder.
Suppose you have the following directory structure:
project_folder/
word_to_pdf.py
input_documents/
document1.docx
document2.doc
output_pdfs/
-
Run the script and provide the following paths when prompted:
- Input Folder:
input_documents
- Output Folder:
output_pdfs
- Input Folder:
-
The script will convert
document1.docx
anddocument2.doc
to PDFs and save them in theoutput_pdfs
folder. -
You will find the converted PDFs (
document1.pdf
anddocument2.pdf
) in theoutput_pdfs
folder.
-
Ensure you have the appropriate permissions to access and write to the input and output folders.
-
Make sure Microsoft Word is installed on your system before running the script.
-
This script uses the
docx2pdf
library and works on Windows, macOS, and Linux. -
Feel free to modify the script to suit your specific needs or integrate it into other automation workflows. (MAR)
Contact me if there where problems or submit an issue to be addressed.