Self-Hosting a Private PDF Conversion Service for Enterprise Offices Using Gotenberg and Docker VPS
Converting PDFs is a common requirement in enterprise environments, especially when handling internal documents, reports, or contracts without sending data outside the organization....
Image credit: Pexels · Pixabay Content License
Converting PDFs is a common requirement in enterprise environments, especially when handling internal documents, reports, or contracts without sending data outside the organization. This guide provides a step-by-step approach to building a private, secure, and efficient PDF conversion service using Gotenberg, Docker, and a VPS. By self-hosting, businesses maintain full control over their data, prevent sensitive information leaks, and avoid third-party service costs. With a Docker-based architecture, deployment is straightforward, easy to maintain, and scalable according to business needs.
Introduction to Gotenberg and Docker
Gotenberg is an automated PDF conversion service based on headless Chromium, enabling high-quality PDF generation from HTML, Markdown, and other web formats. It supports features such as printing web pages, adding headers and footers, watermarks, and customizing margins and page sizes. Docker simplifies deployment by packaging the application with its runtime environment into lightweight containers, ensuring consistent operation across different systems—from personal computers to VPS or server clusters.
Combining Gotenberg with Docker on a VPS allows enterprises to create a private PDF conversion service that doesn't rely on external providers, enhancing data security and protecting internal documents from exposure. This setup ensures that all document processing remains within the organization's controlled infrastructure.
Requirements and VPS Setup
To deploy this service, you need a VPS with at least 2GB RAM and 1 vCPU, preferably using NVMe storage to ensure high I/O performance when handling multiple PDF conversion requests. You can choose a VPS from the NVMe Cloud VPS for Docker, Nginx & Databases service for optimal configuration for containerized applications.
First, log in to your VPS via SSH and update the system:
sudo apt update && sudo apt upgrade -y
Install Docker if it's not already present:
sudo apt install docker.io -y
sudo systemctl enable docker
sudo systemctl start docker
Verify Docker is running with the following command:
sudo docker --version
Deploying Gotenberg with Docker
Gotenberg provides an official Docker image on Docker Hub. To deploy, create a `docker-compose.yml` file in your working directory:
version: '3.8'
services:
gotenberg:
image: thecodingmachine/gotenberg:9
ports:
- "3000:3000"
volumes:
- ./storage:/app/storage
restart: unless-stopped
Explanation:
image: thecodingmachine/gotenberg:9: Uses version 9 of Gotenberg.ports: Exposes port 3000 for API access.volumes: Mounts a local directory to persist data across container restarts.
Start the service using:
sudo docker-compose up -d
After startup, Gotenberg will be ready to accept PDF conversion requests via API at http://.
Converting PDFs via API
Gotenberg provides a REST API to send conversion requests. For example, to convert an HTML file to PDF:
curl -X POST http://:3000/convert/html \
-F "files=@/path/to/your/file.html" \
-F "format=pdf"
To test the service, you can use a simple cURL command or write a small script to call the API. The API supports multiple input formats, including HTML, Markdown, and other web-based formats.
Ensuring Security and Optimization
To ensure security, you should:
- Set up a firewall (UFW) to allow only port 3000.
- Use Nginx as a reverse proxy with HTTPS to secure connections.
- Assign a custom domain and use Let's Encrypt to obtain free SSL certificates.
- Apply resource limits to the Docker container to prevent excessive CPU or RAM usage.
Refer to the guide on optimizing VPS as a dedicated database server to apply performance tuning techniques to your VPS.
Troubleshooting and Verification
If the service does not work:
- Check container status:
sudo docker ps - Review logs:
sudo docker logs gotenberg - Test network connectivity:
ping - Verify port listening:
sudo netstat -tuln | grep 3000
If there are permission issues with the storage directory, ensure the `storage` folder has write permissions for the Docker user.
References
Recommended NVMe Cloud VPS Plans to Deploy This Setup
Enterprise RAID 10 NVMe SSDs, CMC & FPT District 9 uplinks with Anycast Anti-DDoS and 99.99% SLA.
VPS-3E
10% VAT included
- CPU: 2 vCPU
- RAM: 4 GB
- SSD: 50 GB NVMe
