This project is a simple web application that allows users to upload PDF files, which are then processed and converted to DOCX format. The application is built using Flask and includes a minimal front-end with HTML and CSS to provide an easy-to-use interface for file uploads.
- Upload a PDF file from your local system.
- Convert the uploaded PDF file into DOCX format.
- Clean and responsive design with a fixed background image.
- Built using Flask for Python backend.
- CSS styling for the front-end to ensure a user-friendly experience.
Before you begin, ensure that you have met the following requirements:
- Python 3.6 or higher
- Flask library installed
- A text editor or IDE for editing the code (e.g., Visual Studio Code, PyCharm, etc.)
Follow these steps to set up the project on your local machine.
You can clone the project repository using the following command:
git clone https://github.com/yourusername/pdf-to-docx-converter.git
cd pdf-to-docx-converterAlternatively, download the project files as a ZIP and extract them to a directory.
It's good practice to set up a virtual environment for your project to manage dependencies. Run the following commands:
python -m venv venv
source venv/bin/activate # On macOS/Linux
venv\Scripts\activate # On WindowsEnsure you have Flask installed. If it’s not installed yet, run the following command to install it:
pip install flaskIf you want to process the uploaded PDF to DOCX (e.g., use a library like pdf2docx), you can install it using the following command:
pip install pdf2docxTo run the Flask app, navigate to the project directory and execute the following command:
python app.pyFlask will start the development server, and you can access the web app by opening your browser and visiting the following URL:
http://127.0.0.1:5000/
Once the app is running:
- Go to the URL
http://127.0.0.1:5000/in your web browser. - You will see a form asking you to upload a PDF file.
- Choose a PDF file from your local system and click the "Convert PDF to DOCX" button.
- The file will be uploaded to the server, and you’ll receive a success message (or error if something goes wrong).
The uploaded PDF will be stored in the uploads folder in your project directory.
Currently, the app only handles file uploads. You can extend the upload_file route to add PDF-to-DOCX conversion using libraries like pdf2docx. Example conversion:
from pdf2docx import Converter
def convert_pdf_to_docx(pdf_file_path, docx_file_path):
cv = Converter(pdf_file_path)
cv.convert(docx_file_path, start=0, end=None)
cv.close()Here is an overview of the project structure:
your_project/
│
├── app.py # Main Python file with Flask application logic
├── templates/ # Folder containing HTML files
│ └── index.html # HTML file for the upload form
├── static/ # Folder containing static assets (e.g., CSS, images)
│ └── styles.css # External CSS file for styling
├── uploads/ # Folder to store uploaded files (e.g., PDFs)
└── venv/ # (Optional) Virtual environment folder (if used)
- app.py: Contains the main application code to handle routes and file uploads.
- templates/: Contains the HTML templates for the front end of the app.
- static/: Contains static files like stylesheets and images.
- uploads/: The folder where uploaded PDF files are stored temporarily.
You can configure the following parameters for your Flask app:
- UPLOAD_FOLDER: This is the directory where uploaded files will be stored. The default is set to a folder called
uploads. You can change the directory path to another location if needed.
UPLOAD_FOLDER = 'uploads'- Flask debug mode: By default, Flask is in debug mode for easier development. You can disable it in production environments by setting
app.debug = False.
This project is licensed under the MIT License - see the LICENSE file for details.
- This project uses Flask, a micro-framework for Python. It's easy to extend the application with additional features (like PDF-to-DOCX conversion or even serving a front-end built with frameworks like React).
- Security: Make sure to implement proper file handling and validation before deploying the app to production (e.g., checking file types, file size, etc.).
- Error Handling: Improve the user experience by adding more error messages when files fail to upload or are of the wrong type.
Feel free to modify and extend this application according to your requirements. If you encounter any issues, feel free to reach out or create an issue in the project’s GitHub repository.