Files
overleaf-cep/server-ce/Dockerfile-png2pdf
David Rotermund c7eb257a53 Restoring the support images: \n png2pdf: \n Without this cache you need to convert png to pdf manualy or you risk a compile timeout (had this problem yesterday and did the conversion manualy. Compile time reduction was from time out to 3sec.)\n env settings required:\n (mount point INSIDE the container)\n CLSI_CACHE_PATH: /var/lib/overleaf/data/cache \n (Mount point outside of the container i.e. host, based on your compose volume rules)\n SANDBOXED_COMPILES_HOST_DIR_CACHE: points to the same folder outside of the container\n Test parameter:\n PNG2PDF_MIN_FILE_SIZE_BYTES: 1024 \n ENABLE_PNG2PDF_CONVERSIONS: true \n PNG2PDF_IMAGE: sharelatex/png2pdf:2026-06-24 \n\n It acts on slow png conversions and not all. Hence the texlive image needs this detection hook as the creator intended it. I added them to:\n https://github.com/davrot/texlive-full/tree/png2pdf-slow \n It is a modification of the LatexMK file. Without the hook no png files are cached as pdf.\n\n pdftocairo: \n The creater intended that pdf to thumbnail / preview are created by an external container for safety reasons. \n The only action we do a to-thumbnail-conversion is in the template generation. Since we don't want to disapoint the creater, I restored this safety feature.\n env settings required:\n (default: local imagemagick; other options are local pdftocairo and container pdftocairo via pdftocairo-sandbox)\n CONVERTER: pdftocairo-sandbox \n CONVERSION_SANDBOX_IMAGE: sharelatex/pdftocairo:24.02 \n (mount point INSIDE the container)\n CONVERSION_SANDBOX_DIR: /var/lib/overleaf/tmp/conversions \n (Mount point outside of the container i.e. host, based on your compose volume rules)\n CONVERSION_SANDBOX_HOST_DIR: points to the same folder outside of the container\n
2026-10-24 14:30:35 +00:00

52 lines
2.5 KiB
Plaintext

# replacement for quay.io/sharelatex/png2pdf:2026-06-24 (clsitex PNG→PDF)
#
# Engine: img2pdf (josch) — lossless. For PNG input the IDAT streams are
# embedded verbatim into the PDF (no re-encode); the alpha channel becomes
# a PDF soft mask (/SMask), also lossless. That is the mechanism of the
# whole feature: pdfTeX copies PDF image streams cheaply, while PNGs with
# alpha/gamma/palette/interlace are re-decoded on every compile, which is
# what made them "slow" and what fills CLSI's slow-PNG list.
#
# The SaaS tool is proprietary. The Go port (go/services/clsitex/png2pdf)
# pins the exact container contract this image fulfils:
# ENTRYPOINT + ["--in-place", "--", "<relpath>", ...] CWD=/compile
# stdout: one "Converted <f> to PDF" line per file (counted by Go)
# exit non-zero on first failure (CLSI falls back to the original PNGs)
#
# Why git@commit instead of `pip install img2pdf==0.6.3`:
# 0.6.3 (2025-11-06) is the last PyPI release, and it PRE-DATES the
# parse_png quadratic-rewrite fix (2025-11-16, "my 311MB ARCHD at 600dpi
# with 17638 IDAT records went from many minutes to 320ms"). The slow-PNG
# list is populated by BIG PNGs (min 1MB, no upper bound), so we pin main
# at this commit: it is still reproducible (exact hash) and carries the
# fix plus the JPEG2000/ICC and pikepdf-writer-close follow-ups.
#
# pikepdf + pillow have musllinux cp314 wheels for this python version, so
# no compiler is needed; git is needed only for the pinned checkout.
FROM python:3.14-alpine
ARG IMG2PDF_REF=0fafa2c312be50c68a07e2331a89bf4adbd274ed
RUN apk update \
&& apk add --no-cache git \
&& pip install --no-cache-dir --disable-pip-version-check \
"git+https://gitlab.mister-muffin.de/josch/img2pdf.git@${IMG2PDF_REF}#egg=img2pdf" \
pikepdf==10.15.0 \
pillow==12.3.0 \
packaging \
&& rm -rf /root/.cache/pip /usr/src/python/lib*
# shim: arg parsing, leading-dash path handling (paths derive from URL
# paths and start with '-'), temp-file + atomic replace (input must survive
# a failed conversion — CLSI renames the untouched original as fallback),
# and the "Converted <f> to PDF" stdout line Go counts.
COPY server-ce/png2pdf/png2pdf.sh /usr/local/bin/png2pdf
RUN chmod 0755 /usr/local/bin/png2pdf
# The Go runner passes the arg list ["--in-place", "--", ...] as the container
# command, never a binary name — see the pdftocairo image (ENTRYPOINT []) for
# the contrast: that image provides the binary NAME in its command, this one
# relies on the image's own ENTRYPOINT.
ENTRYPOINT ["/usr/local/bin/png2pdf"]