Generate a printable PDF almanac from structured JSON data using Jinja2 templates and WeasyPrint.
- Python 3.10 or newer
uv
for managing the virtual environment and dependencies (preferred)- System packages required by WeasyPrint (e.g.
libpango
,cairo
,gdk-pixbuf
, andlibffi
). Refer to the WeasyPrint installation guide for your platform.
-
Install uv (skip if you already have it):
curl -LsSf https://astral.sh/uv/install.sh | sh
After installation, ensure that
uv
is on yourPATH
(restart your shell if necessary). -
Install project dependencies:
uv sync
This command creates an isolated virtual environment (by default at
.venv/
) and installs the packages listed inpyproject.toml
.
Generate the PDF almanac with:
uv run python main.py
The script reads data.json
, renders the index.html
template with Jinja2, applies style.css
, and saves the resulting PDF as almanac.pdf
in the project root.
Note on fonts: the first run downloads the open-source Abhaya Libre font into the local
fonts/
directory so that Sinhala text renders correctly. Subsequent runs reuse the cached files. If the download fails (e.g. offline environments), the script warns and falls back to the fonts already available on your system.
- Update
data.json
to change the content rendered into the template. - Modify
index.html
to adjust the HTML layout or include new data fields. The Jinja2 environment is configured withStrictUndefined
, so missing values will cause a helpful error. - Edit
style.css
to tweak typography or layout in the final PDF.
Run uv run python main.py
again after making changes to regenerate the PDF.
- If uv reports missing system libraries during installation, install the required packages using your OS package manager and rerun
uv sync
. - For PDF rendering issues, check the console output for template or JSON errors and verify that all paths referenced in the template exist.