
Seamlessly convert Microsoft Word documents (.DOC/.DOCX) to PDF programmatically via a REST API
- Ensure you have the latest stable version of Docker Compose installed on your machine:
docker compose versionNote: The initial build may take a while as LibreOffice is a large dependency. Subsequent builds and container starts will be near-instant due to Docker's layer caching.
docker compose up- Install the test dependencies inside the running container:
docker exec -it flask_api poetry install --with test- Run the test suite:
docker exec -it flask_api poetry run pytest -rfsxE --capture=no --log-cli-level=DEBUG --maxfail=1 ./test- Navigate to http://localhost:5000/doc_to_pdf.
- Select a local DOC or DOCX file (e.g. dummy_doc.docx).
- Click the Upload button.
- Check that the resulting PDF either appears directly in the browser or starts downloading automatically.
- Complete the Quickstart and ensure the server is already up and running.
Note: Since Flask is running in debug mode, the server will automatically reload whenever changes are saved to server.py.
- Ensure you have the latest stable version of Python installed:
python --version- Create a Virtual Enviroment:
python -m venv .venv- Activate the Virtual Enviroment:
activate_venv() {
if [[ $(uname) == "Darwin" ]]; then
source .venv/bin/activate
elif [[ $(uname) == "Linux" ]]; then
source .venv/bin/activate
elif [[ $(uname) == CYGWIN* || $(uname) == MINGW* ]]; then
source .venv/Scripts/activate
else
echo "Unsupported operating system"
fi
}
activate_venv- Ensure the Virtual Enviroment is active:
PYTHON_PATH=$(which python)
if [[ "$PYTHON_PATH" == *".venv"* ]]; then
echo "Python is using a .venv environment: $PYTHON_PATH"
else
echo "Python is NOT using a .venv environment: $PYTHON_PATH"
fi- Install the Poetry package manager:
pip install poetry- Install the project dependencies from all dependency groups:
poetry install --with test,format- The test and task commands will now run without the
docker exec -it flask_apiprefix.
- Install the required dependencies inside the running container:
docker exec -it flask_api poetry install --with format- Run the formatting task:
docker exec -it flask_api poetry run python ./tasks/format.py