A full-stack website application to convert a word document into either pdf, XML, or text format.
Tech stack : HTML5, CSS3, JavaScript, FastApi, Python, AJAX, jQuery
- Take a word document and the required format as input.
- Convert that file into the required format among any of the three formats XML, text, or pdf.
- Return the converted file with the same name as that of the input which can be viewed as well as downloaded
- Releases log messages for every action it starts performing. Hence easy to debug and fix the error when generated.
- docx2txt==0.8 for converting to text format
- docx_util for converting to XML format
- docx2pdf for converting to pdf format
- Step 1 : Select the docx file by clicking on the button or drag and drop the file
- Step 2 : Choose the required format from XML, pdf, or txt by clicking on their respective image. When it will be selected there will be a dark purple background signifying that the format has been chosen. Since those are radio buttons only one will be selected at a time.
- Step 3 : Click on the convert button and it will start converting your file landing you on the loading page.
Your task is now finished. Simply relax as your file will be converted in just a fraction of a second.
- Step 4 : You will be taken to a different page where you can view your converted file.
- Step 5 : Finally, you can download your converted file by clicking on the download button.
Get the code here .
Backend part has been implemented using FastAPI. FastAPI is a modern, fast (high-performance), web framework for building APIs with Python 3.6+ based on standard Python type hints.
- Create a virtual environment after deciding a directory where you want to place it, and run the venv module as a script with the directory path:
python3 -m venv local-env
- Once you’ve created a virtual environment, follow below command on Windows to activate it as
local-env/scripts/activate
Or on Unix or MacOS.
source local-env/bin/activate
- Installs all of the modules listed in my Python requirements file into your project environment using
pip install -r requirements.txt
- Make a small changes in the main.py file present inside backend directory. Replace
return {"Destination File Path": dest_file}
with
return {"Destination File Path": f"{SERVER_ADDRESS}/output_files/{dest_file}"}
- Navigate to the backend directory and then run your application using the below command:
uvicorn main:app --reload
- You can now go to the below URL and try uploading the file and format
http://127.0.0.1:8000/docs
- Click on "Try it out" in top right corner as shown in the image.
- Now choose the file by clicking on "Choose File" input, enter the required format, and click on the "Execute" button.
- As soon as you click on the "Execute" button, the program will start its execution and return you a destination file path as the response.
- Go to the URL provided in the response body as above and you will get your converted file. Url is like:
127.0.0.1:8000/output_files/sample05082022_212849.pdf