Bundled images and scaling
==========================
``POST /pdf/generate/bundle`` accepts an HTML or Markdown request and separate
binary image files in one authenticated multipart upload. Templates reference
image names; neither the template nor the request JSON needs base64 data URLs.
The existing JSON ``/pdf/generate`` endpoint is unchanged.
Request format
--------------
Send one text field named ``request`` containing the same JSON object documented
in :doc:`generate`, and one or more file parts named ``assets``. Each file part's
``filename`` is its logical name, including any relative directories. All names
are relative to the bundle root, including URLs in the inline CSS template.
Template ``filename`` metadata does not change this root.
For example, a local directory can contain:
.. code-block:: text
request.json
assets/
logo.svg
portrait.jpg
``request.json``:
.. code-block:: json
{
"html_template": {
"content": "
"
},
"css_template": {
"content": ".logo {width:40mm;height:15mm;object-fit:contain} .portrait {width:35mm;height:45mm;object-fit:cover;object-position:center}"
}
}
Upload with curl after obtaining the usual bearer token:
.. code-block:: bash
curl --fail-with-body "$INFLUXION_BASE_URL/pdf/generate/bundle" \
-H "Authorization: Bearer $TOKEN" \
-F 'request=
.. code-block:: markdown
{ width=160 }
.. code-block:: css
.banner { background: url("assets/banner.png") center / cover no-repeat; }
Names are case-sensitive, at most 200 characters, and contain only ASCII letters,
digits, slashes, dots, underscores and hyphens. Absolute paths, backslashes,
``.``/``..`` path segments, percent escapes, queries and duplicate names are
rejected. Missing named images, including references inside SVG or CSS, put the
job in ``Error`` with a useful message. A partial PDF cannot be downloaded.
Use conditional template markup when an image is optional.
The renderer resolves names against an internal virtual origin through the
restricted URL fetcher. It never uses a template URL to open an arbitrary server
file. Absolute remote URLs and existing data URLs retain the deployment's URL
policy. Set ``INFLUXION_URL_ALLOWLIST=none`` (Helm: ``urlFetch.allowlist: none``)
when documents should use only bundled and inline resources. Do not override
the document's base URL with an HTML ```` element when using bundle names.
Scaling and image quality
-------------------------
Control the printed size in CSS. ``width`` with ``height:auto`` preserves the
intrinsic aspect ratio. Use ``mm`` or ``cm`` for predictable physical sizes;
``max-width:100%`` keeps ordinary document images within their container.
.. code-block:: css
img { max-width: 100%; height: auto; }
.logo {
width: 40mm;
height: 15mm;
object-fit: contain; /* whole image, no stretching or cropping */
}
.portrait {
width: 35mm;
height: 45mm;
object-fit: cover; /* fill the box and crop overflow */
object-position: center; /* choose the crop's focal point */
}
For CSS backgrounds, use ``background-size:contain`` or ``cover`` instead.
SVG logos remain vector graphics in the PDF. Raster images keep their source
resolution; changing their CSS size cannot add detail. For 300 DPI at 40 mm wide,
provide at least 473 pixels of width. Bundling does not resize or recompress files
and does not introduce a second scaling parameter alongside CSS.
Limits and storage
------------------
* At most 32 images, 20 MiB per image and 20 MiB combined image bytes.
A lower ``INFLUXION_URL_FETCH_MAX_BYTES`` further limits each image.
* At most 1 MiB of request JSON and 22 MiB for the complete multipart body,
including chunked uploads. Oversized bodies are rejected before multipart
parsing. The raw upload and large file parts spool to temporary disk.
* Static PNG, JPEG, WebP and UTF-8 SVG are supported. The image bytes are
checked for format structure, dimensions and decodability; a declared media
type must match, or be ``application/octet-stream``. Pillow can accept
recoverable JPEG scan damage as a decodable image.
* Raster images are limited to 40 million pixels. Animated images, malformed
images and SVG documents containing a DTD or entity declarations are rejected.
* Bad names, duplicate names, invalid JSON and raster decode/verification errors
return ``422``; unsupported formats, invalid SVG or mismatched media types
return ``415``; byte/pixel limits return ``413``.
Multipart parser limits, such as too many parts, return ``400``.
Uploads are staged under a random job-scoped directory in
``INFLUXION_PDF_RUNTIME_DIR``. Generated storage filenames are independent of
logical names. Celery receives a bundle identifier rather than image bytes.
The app and workers must share that runtime volume, as in the supplied Compose
and Helm configurations; a separate worker machine needs shared storage.
Images are deleted after generation, including failures. Rejected requests,
duplicate document IDs and dispatch failures remove their staged images too.
Orphans older than 24 hours are removed on app startup and before the next
bundle upload; this is opportunistic cleanup, not a background timer. Queued
bundle jobs must start within 24 hours. Downloaded PDFs retain the existing
short PDF retention policy. There is no permanent image library or image URL.
Invoice and profile examples
----------------------------
The examples use the supplied invoice/profile layouts and named images, with
fictitious document data. The profile portrait is a provided example image;
replace it when adapting the example.
.. code-block:: bash
python docs/examples/generate_bundle.py invoice --dry-run
python docs/examples/generate_bundle.py profile --dry-run
python docs/examples/generate_bundle.py invoice -o output/pdf/invoice.pdf
python docs/examples/generate_bundle.py profile -o output/pdf/profile.pdf
The script reads ``INFLUXION_CLIENT_ID``, ``INFLUXION_CLIENT_SECRET`` and optional
``INFLUXION_SCOPE`` from the environment or project ``.env``. The server defaults
to ``INFLUXION_BASE_URL`` or ``http://localhost:8000``; override with ``--base-url``.
* :download:`Multipart example client <../examples/generate_bundle.py>`
* Invoice: :download:`HTML <../examples/invoice/invoice.html>`,
:download:`CSS <../examples/invoice/invoice.css>`,
:download:`data <../examples/invoice/invoice-data.json>`,
:download:`SVG logo <../examples/invoice/assets/logo.svg>`.
Its logo scales proportionally in the header and continuation-page header.
* Profile: :download:`HTML <../examples/profile/profile.html>`,
:download:`CSS <../examples/profile/profile.css>`,
:download:`data <../examples/profile/profile-data.json>`,
:download:`portrait <../examples/profile/assets/portrait.jpg>`,
:download:`background <../examples/profile/assets/hero-background.png>`,
:download:`logo <../examples/profile/assets/logo.png>`.
Its portrait uses a square ``cover`` crop and its footer logo preserves aspect
ratio across pages.