Background. I am dockerizing my Django app. One thing it does is generate xlsx spreadsheets or pdf representations thereof. The sheet is generated by openpyxl, and if the user wants PDF the generated sheet is converted by using subprocess.run to invole Libreofficde in headless mode
libreoffice --headless --convert-to pdf --outdir "$1" "$2"
all of which works perfectly on my development server, without Docker.
The top of my Dockerfile looks like this:
FROM ubuntu:24.04
RUN echo 'APT::Install-Suggests "0";' >> /etc/apt/apt.conf.d/00-docker
## RUN echo 'APT::Install-Recommends "0";' >> /etc/apt/apt.conf.d/00-docker
RUN DEBIAN_FRONTEND=noninteractive
apt-get update
&& apt-get install -y python3 python3-venv postgresql-client libreoffice-calc
&& rm -rf /var/lib/apt/lists/*
My understanding is that the RUN echo
lines tell apt-get to install neither suggested nor recommended packages to keep the image size smaller.
As shown, it all again works well.
If I uncomment the ## line, everything works well except Libreoffice inserts a column split into the generated pdf so one spreadsheet column is on the second page!
I chose an LTS version of Ubuntu for stability (and because of the example I had cribbed). I’m much more familiar with Fedora and DNF. Anyway,
-
Does anyone immediately recognise why this is happening and how to fix it?
-
How do I get a list of what extra packages are being pulled in as recommendations? Because I suspect that out of something like 300Mb of stuff, there’s one small Libreoffice or system-environment component which makes the difference.
-
Is there any other (free) way to convert xlsx to pdf than using LibreOffice? (It works well but it bloats the image).
I suspected it might be a system locale problem, but locale
in both versions prints exactly the same. On a wild guess, I tried explicitly prefixing LC_PAPER=en_GB.utf8
to the libreoffice conversion command, but to no avail.
Afterthought, Is there a simple way to inspect a pdf file and determine how many pages it contains, so I can write a test for this misbehaviour?