Skip to main content

Convert documents between formats. For example docx to html or pdf to html

Project description

unoserver-fastapi

Introduction

This server creates API access to Unoserver (LibreOffice) using FastApi.

Further unoserver documentation

Installation

We recommend that you use the provided Dockerfile, as the server requires LibreOffice, Unoserver, etc. And the integration of Unoserver with the python libraries is not straightforward. Install Docker and familiarise yourself with it.

docker build -t unoserver-fastapi:v0 .
docker run unoserver-fastapi:v0

Or using docker-compose

docker-compose build --no-cache
docker-compose up

Local execution

  1. Install the local environment using the Pipfile provided. Be aware that it is using python 3.11:
pipenv install --dev
  1. Run the script for the unoserver required library (tested in linux [Ubuntu]):
# Make the script executable
chmod +x allocate_local_unoserver.sh

# Run the script
./allocate_local_unoserver.sh

# After that, you should be able to run the unoserver locally and you can test it with this command:
./environments/virtenv/bin/python3 -m unoserver.server --interface localhost --port 2024
  1. Local run
pipenv shell

gunicorn main:app --workers 2 -b :5000 -k uvicorn.workers.UvicornWorker --timeout 60

Fonts

You may encounter a font issue with certain documents (ex: pdf). One option is to bring fonts from Windows into your system.

  • Copy the fonts under C:\Windows\Fonts (removing the .fon files)

  • Paste them in /usr/share/fonts/win (create the folder yourself)

  • Update the font cache running on the previous folder

    # These commands require xfonts-utils:  sudo apt-get install xfonts-utils
    mkfontscale
    mkfontdir
    fc-cache
    

System Service

To create a system service for unoserver:

nano /etc/systemd/system/unoserver.service

Copy inside the following:

[Unit]
Description=unoserver
After=network.target
 
[Install]
WantedBy=multi-user.target
 
[Service]
Type=simple
User=root
Group=root
ExecStart=/usr/local/bin/unoserver
Environment=PYTHONUNBUFFERED=true
Restart=on-failure
RestartSec=3

To take effect: systemctl daemon-reload

To make the service on startup: systemctl enable daemon-reload

Notes:

  • If executed on a multi-core machine, run several unoservers with different ports. here is however no support for any form of load balancing in unoserver, you would have to implement that yourself in your usage of unoconverter. For performant multi-core scaling, it is necessary to specify unique values for each unoserver's --port and --uno-port options.
  • A next step may include managing multiple unoservers for the requests.
  • Only LibreOffice is officially supported. Other variations are untested.
  • Some samples have been downloaded from sample-videos.com

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

doc2html-0.0.1.tar.gz (2.8 MB view details)

Uploaded Source

Built Distribution

doc2html-0.0.1-py3-none-any.whl (33.2 kB view details)

Uploaded Python 3

File details

Details for the file doc2html-0.0.1.tar.gz.

File metadata

  • Download URL: doc2html-0.0.1.tar.gz
  • Upload date:
  • Size: 2.8 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.11.7

File hashes

Hashes for doc2html-0.0.1.tar.gz
Algorithm Hash digest
SHA256 117fcc65fba01528767a33f424b5c0cb4bfd5aa4d6c090c45a81c71dc90f7eab
MD5 a9fad517adde7429195c25e3b214363d
BLAKE2b-256 5370621905f21a4dd44d81dd0d07f629b4d3b899c90b31a6e4d92de3a8f256f1

See more details on using hashes here.

File details

Details for the file doc2html-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: doc2html-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 33.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.11.7

File hashes

Hashes for doc2html-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 61a599b18c42214240a6b1e743462e964e01e818e1e551882fa5480528b78fbd
MD5 794f8b73ebd6a9203443a84f834cc04f
BLAKE2b-256 8613f80e48a8a6fe08c9b72c082091181b47b903df860638e70771cbdbd60687

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page