Skip to main content

PDF generation via LaTeX — structured data in, professional documents out

Project description

English version: README.en.md

Klartex

PDF-generering via LaTeX — strukturerad data in, professionella dokument ut.

klartex.se · PyPI · GitHub

Klartex tar JSON-data + mallnamn och producerar PDF via XeLaTeX. Kan användas som Python-bibliotek, CLI-verktyg eller HTTP-tjänst.

Mallar

Mall Beskrivning
_block Universell blockmotor — agenten komponerar dokumentet fritt
protokoll Mötesprotokoll med dagordning, beslut och justerare
faktura Faktura med rader, moms och betalningsinformation

Installation

# Som globalt CLI-verktyg
pipx install klartex

# Eller i ett projekt
pip install klartex

Kräver Python ≥ 3.12 och XeLaTeX (brew install --cask mactex eller apt install texlive-xetex).

Användning

Som Python-bibliotek

from klartex import render

pdf_bytes = render("protokoll", data)

Som CLI

# Rendera (block engine är default)
klartex -d data.json

# Pipe JSON via stdin
cat data.json | klartex

# Med explicit mall
klartex -d data.json -t protokoll

# Med extern sidmall
klartex -d data.json --page-template minforening.tex.jinja

# Lista mallar
klartex templates

# Visa JSON Schema för en mall
klartex schema protokoll

# Starta HTTP-server
klartex serve

Som HTTP-tjänst

klartex serve --port 8000
# Rendera PDF
curl -X POST http://localhost:8000/render \
  -H "Content-Type: application/json" \
  -d '{"template": "protokoll", "data": {...}}' \
  -o output.pdf

# Rendera med extern sidmall
curl -X POST http://localhost:8000/render \
  -H "Content-Type: application/json" \
  -d '{"template": "_block", "data": {...}, "page_template_source": "\\definecolor{brandprimary}{HTML}{2E5A1C}\\n..."}' \
  -o output.pdf

# Lista mallar
curl http://localhost:8000/templates

# Hämta schema
curl http://localhost:8000/templates/protokoll/schema

Sidmallar (Page Templates)

Sidmallar styr sidhuvud, sidfot, färger och logotyp. Tre inbyggda finns:

Sidmall Beskrivning
formal Organisationsnamn och kontaktinfo i sidhuvud, logotyp, sidnummer i sidfot
clean Enbart logotyp i sidhuvud, sidnummer i sidfot
none Inget sidhuvud, enbart sidnummer i sidfot

Egen sidmall

Skapa en .tex.jinja-fil som definierar \fancyhead/\fancyfoot:

\definecolor{brandprimary}{HTML}{2E5A1C}
\definecolor{brandsecondary}{HTML}{555555}
\providecommand{\orgname}{}
\renewcommand{\orgname}{Min Förening}
\makeatletter
\fancyhead[L]{\fontsize{6pt}{9pt}\selectfont\textbf{\orgname}}
\fancyhead[R]{\includegraphics[height=0.855cm]{logo.pdf}}
\fancyfoot[C]{%
    \kx@setlang%
    \fontsize{6pt}{9pt}\selectfont\color{brandsecondary}%
    \doctitle\ \textbullet\ \kx@page\ \thepage\ \kx@of\ \pageref{LastPage}%
}
\makeatother

Använd sedan --page-template minforening.tex.jinja i CLI eller "page_template_source": "..." i API-anrop. Logotyper och andra filer hittas relativt till arbetsmappen.

Arkitektur

Klartex har en trelagers-arkitektur:

  1. Dokumentnivåklartex-base.cls hanterar siduppställning och grundläggande sidhuvud/sidfot. Sidmallar (.tex.jinja) injiceras i preambeln och styr färger, logotyp och layout.
  2. Komponentnivå — Återanvändbara .sty-paket som ger strukturerade LaTeX-makron (t.ex. klartex-signaturblock.sty, klartex-klausuler.sty, klartex-agenda.sty)
  3. Receptnivå — YAML-filer som deklarerar vilka komponenter och innehållsfält som ska kombineras

Renderingsvägar

  • Recipe-mallar (protokoll, faktura) — YAML-recept som deklarerar komponenter och mappningar
  • Block engine (_block) — Agenten komponerar body[] fritt från typade block

Skapa en YAML-receptmall

Skapa en recipe.yaml i mallens katalog (t.ex. klartex/templates/min-mall/recipe.yaml):

template:
  name: min-mall
  description: "Beskrivning av mallen"
  lang: sv

document:
  title: "{{ data.title }}"
  page_template: formal
  metadata:
    - label: "Datum:"
      field: date

components:
  - type: klausuler
    data_map:
      items: agenda_items
    options:
      item_title_field: title
      item_body_field: body

schema: schema.json

Tillgängliga recept-komponenter: heading, metadata_table, attendees, klausuler, signaturblock, titelsida, adjuster_signatures, invoice_header, invoice_recipient, invoice_table, payment_info, invoice_note.

Block engine-block: heading, text, title_page, parties, clause, signatures, metadata_table, attendees, agenda, name_roster, adjuster_signatures, page_break, latex.

Licens

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

klartex-0.1.0.tar.gz (26.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

klartex-0.1.0-py3-none-any.whl (42.1 kB view details)

Uploaded Python 3

File details

Details for the file klartex-0.1.0.tar.gz.

File metadata

  • Download URL: klartex-0.1.0.tar.gz
  • Upload date:
  • Size: 26.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.5

File hashes

Hashes for klartex-0.1.0.tar.gz
Algorithm Hash digest
SHA256 b70d76548f3f2961053a3bf144822f2c8d3351aa118332deb4f0a2c451c1cd8d
MD5 d13897f36bae0229ef54cf1d5ea5c6fb
BLAKE2b-256 dd62d38bf892edca63b9bd4a75bb2d227dc1702a688bc8237f182f55a264207d

See more details on using hashes here.

File details

Details for the file klartex-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: klartex-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 42.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.5

File hashes

Hashes for klartex-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f5cddf78cefc312f7d4bfe0809b58db9041b05029b6d72b829709f42f933875c
MD5 15c912aba579912a6b43e446a8b5f0df
BLAKE2b-256 6597f8499d80f5451fff67d97463748253847daed9123c2a5ea65df1cd1923cf

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page