api.utils.pdf_compression ========================= .. py:module:: api.utils.pdf_compression .. autoapi-nested-parse:: Shrinking a PDF with Ghostscript, for uploads that exceed a size limit (Shopify's Files storage refuses anything over 20 MB). Manufacturer manuals are usually heavy because of high-resolution scans and photos: re-rendering them with Ghostscript's ``/ebook`` preset (images downsampled to 150 dpi) typically divides their size by 3 to 10 with no visible loss on screen. Text and vector drawings are kept as is. Ghostscript (``gs``) must be installed -- it is in the Docker image. When it isn't, or when it fails, ``compress_pdf`` returns ``None`` rather than raising: compression is a best-effort attempt and the caller reports the original size problem instead. Attributes ---------- .. autoapisummary:: api.utils.pdf_compression.logger api.utils.pdf_compression.GHOSTSCRIPT_TIMEOUT_SECONDS Functions --------- .. autoapisummary:: api.utils.pdf_compression.compress_pdf Module Contents --------------- .. py:data:: logger .. py:data:: GHOSTSCRIPT_TIMEOUT_SECONDS :value: 180 .. py:function:: compress_pdf(content: bytes) -> bytes | None The PDF re-rendered with Ghostscript's ``/ebook`` preset, or ``None`` when Ghostscript is missing, fails, or doesn't produce a smaller file.