Skip to content

jarrin/unoserver-docker-rest-api

 
 

Repository files navigation

Unoserver Container Image

Container image for unoserver

The environment

This Container image uses Alpine Linux as a base image and provides:

  • LibreOffice

  • unoserver

  • Fonts (Alpine packages)

    • font-noto

    • font-noto-cjk

    • font-noto-extra

    • terminus-font

    • ttf-font-awesome

    • ttf-dejavu

    • ttf-freefont

    • ttf-hack

    • ttf-inconsolata

    • ttf-liberation

    • ttf-mononoki

    • ttf-opensans

How to use it

Note
The docker can normally be replaced with podman as well.

In interactive mode

Just run:

docker run -it -v <your directory>:/data/ ghcr.io/unoconv/unoserver-docker

After you start the container, you can use unoconvert command to convert documents using LibreOffice.

or to convert directly using unoconvert:

docker run -it -v <your directory>:/data/ ghcr.io/unoconv/unoserver-docker unoconvert /data/document.docx /data/document.pdf

Docker maps your directory with /data directory in the container.

You might need to add the option :z or :Z like <your directory>:/data/:z or <your directory>:/data/:Z if you are using SELinux. See Docker docs or Podman docs.

In non-interactive (remote) mode

docker run -p 2003:2003 ghcr.io/unoconv/unoserver-docker

After you start the container, you can use unoconvert command to convert documents using LibreOffice.

Note
You must use --host-location otherwise unoconvert will default to local although running unoserver in a container should be handled as remote.
unoconvert --host-location remote example.docx example.pdf

Using the REST API service

First, build the image with the argument ENABLE_REST_API set to true, or set it in the docker-compose.yml file.

At run time you can set the REST_API_KEY environment variable to a random string. The rest API service will check it against the x-api-key header. It’s not mandatory, but don’t expose the port to the internet in that case.

The API wil be exposed at port 8000, as of now only the /convert endpoint exists.

/convert

Method: Post

Example:

{
    "data": "<base64 string without the mimetype and base664 identifier>",
    "convert_from": "docx/doc",
    "convert_to": "pdf/html",
    "write_to": "stream/base64/file_path",
    "bust": true,
    "overwrite": true
}

FAQ

  1. Why do I get an error during when converting is writing/exporting to file?

  2. It’s very likely that you haven’t given the container write permission to the mounted data directory. See: Issue #44

How to contribute / do it yourself?

Requirements

You need the following tools:

  • A bash compliant command line

  • Docker installed and in your path

How to build

docker build .

About

Docker files for a dockerized unoserver

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages

  • Python 69.2%
  • Dockerfile 15.7%
  • Shell 15.1%