Last active
January 30, 2025 18:01
-
-
Save eugene1g/74172a761e604d875a59774189aafb68 to your computer and use it in GitHub Desktop.
Dockerfile for LibreOffice to convert DOCX files to PDF
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FROM docker.io/library/almalinux:latest | |
# LibreOffice version - find the latest at https://downloadarchive.documentfoundation.org/libreoffice/old/latest/rpm/x86_64/ | |
ARG LIBREOFFICE_VERSION=25.2.0.3 | |
ENV LIBREOFFICE_VERSION=${LIBREOFFICE_VERSION} | |
# Install all dependencies for LibreOffice | |
RUN dnf install -y epel-release almalinux-release-devel && \ | |
dnf update -y && \ | |
dnf install -y java-21-openjdk libXinerama cairo cups xorg-x11-font-utils cabextract | |
# Download and install LibreOffice | |
RUN curl -L \ | |
"https://downloadarchive.documentfoundation.org/libreoffice/old/$LIBREOFFICE_VERSION/rpm/x86_64/LibreOffice_${LIBREOFFICE_VERSION}_Linux_x86-64_rpm.tar.gz" \ | |
-o libreoffice.tar.gz && \ | |
tar xzf libreoffice.tar.gz && \ | |
dnf install -y LibreOffice_${LIBREOFFICE_VERSION}_Linux_x86-64_rpm/RPMS/*.rpm && \ | |
rm -rf libreoffice.tar.gz LibreOffice_${LIBREOFFICE_VERSION}_Linux_x86-64_rpm && \ | |
ln -sf $(ls -d /opt/libreoffice*/program/soffice | head -n1) /usr/local/bin/soffice | |
# Install MS TrueType fonts | |
RUN rpm -i https://sourceforge.net/projects/mscorefonts2/files/rpms/msttcore-fonts-installer-2.6-1.noarch.rpm/download | |
# Create a working directory for file operations | |
WORKDIR /documents | |
# Create a bash script to convert STDIN to PDF | |
COPY <<'EOF' /usr/local/bin/convert.sh | |
#!/bin/bash | |
set -e | |
cat - > "${1:-input_file}" | |
soffice --headless --convert-to pdf:writer_pdf_Export --outdir /documents "${1:-input_file}" | |
cat "${1:-input_file}.pdf" | |
EOF | |
RUN chmod a+x /usr/local/bin/convert.sh | |
ENTRYPOINT ["/usr/local/bin/convert.sh"] | |
# docker build --platform=linux/amd64 -t mylibrepdf . | |
# echo "docker run --rm -i mylibrepdf" > ~/bin/topdf && chmod +x ~/bin/topdf | |
# cat Document.docx | topdf > Document.pdf |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment