Measurement and wrapping
SoulDoc estimates text size, wraps lines to the available width, and can use application-provided Pillow font metrics when precise fonts are available.
SoulDoc is a format-independent document layout and rendering engine for Python. Give it structured content or already calculated geometry, and export the same document to printable HTML, SVG, PDF, editable DOCX, visual XLSX, or JSON.
pip install souldoc
The short explanation
Most document libraries start with one file format. SoulDoc starts with the document itself: its content, structure, pages, geometry, styles, resources, and reading order. Renderers then translate that neutral model into the closest native objects each output format can provide.
MD(...) recordsOne pipeline, two document levels
SoulDoc separates layout decisions from file-format rendering. This keeps the document model understandable and prevents each renderer from calculating a different layout.
SoulDoc estimates text size, wraps lines to the available width, and can use application-provided Pillow font metrics when precise fonts are available.
Flow content moves across pages, tables split by row, and repeated document headers and footers remain part of the same layout pass.
Positioned boxes use millimetres, giving browsers, PDF, Word, and spreadsheets one shared physical coordinate system.
The positioned document can be serialized to JSON, passed between services, stored, validated, and rendered later without repeating layout decisions.
One model, multiple outputs
Self-contained, paginated HTML with fixed page geometry and print CSS.
One SVG per page for inspecting calculated positions and physical dimensions.
The printable HTML is rendered by offline Chromium with HTTP requests blocked.
Native tables and editable text, with positioned text boxes where appropriate.
Cells, merged ranges, text-box shapes, drawings, images, and configured print areas.
A versioned envelope containing pages, positioned boxes, resources, and metadata.
Practical uses
Python examples
The high-level model is the simplest choice when SoulDoc should calculate dimensions, wrap content, and create pages.
from souldoc import (
Column,
SoulLayoutDocument,
SoulStyle,
Table,
Text,
save_document,
)
document = SoulLayoutDocument(
name="Quarterly report",
children=[
Column(
gap_mm=5,
children=[
Text(
"Quarterly report",
style=SoulStyle(
font_size_pt=24,
font_weight="bold",
text_align="center",
),
),
Text("One model can produce every supported format."),
Table(
rows=[
["Product", "Quantity", "Amount"],
["Service A", "12", "$1,200"],
["Service B", "8", "$960"],
],
header_rows=1,
),
],
)
],
)
for extension in ("html", "svg", "pdf", "docx", "xlsx"):
save_document(document, f"report.{extension}")
Use SoulDocument directly when a visual editor, database, or upstream
service already provides page numbers, coordinates, and dimensions.
from souldoc import SoulBox, SoulContentKind, SoulDocument, SoulPage, save_document
document = SoulDocument(
name="Contract",
pages=[
SoulPage(
number=1,
width_mm=210,
height_mm=297,
boxes=[
SoulBox(
id="title",
page=1,
left_mm=20,
top_mm=15,
width_mm=170,
height_mm=20,
content="Contract",
content_kind=SoulContentKind.TEXT,
style="font-size:24pt;font-weight:bold;text-align:center;",
)
],
)
],
)
save_document(document, "contract.pdf")
save_document(document, "contract.docx")
Use Markdown("# Heading") in layout documents or
SoulContentKind.MARKDOWN in positioned records. Ordinary text is
never interpreted as Markdown automatically.
MD(...)
When a record contains an =MD("...") formula, SoulDoc prefers its
evaluated HTML value and provides a dependency-free Markdown fallback if the
value is absent.
External images are loaded only through an application-provided resolver. Optional SHA-256 metadata can be checked before bytes are embedded.
Related tools, different responsibilities
TenTags is a compact declarative language and export engine for tables. SoulDoc is a complete document layout engine. Use them independently, or place TenTags tables inside a larger SoulDoc document.
| Question | TenTags | SoulDoc |
|---|---|---|
| Primary job | Describe and render styled tables | Lay out and render complete documents |
| Typical input | A compact table formula | A component tree or positioned document IR |
| Geometry | Rows, columns, cells, and merges | Pages, flow, free positioning, and physical dimensions |
| Best used for | Tables embedded in applications and templates | Reports, contracts, invoices, forms, and full-page documents |
Install only what you need
No runtime dependencies.
pip install souldoc
Installs Beautiful Soup and python-docx.
pip install "souldoc[docx]"
Installs Pillow and XlsxWriter.
pip install "souldoc[xlsx]"
Install the extra, then install Chromium once.
pip install "souldoc[pdf]"
playwright install chromium
DOCX, XLSX, PDF, font measurement, HTML, SVG, and JSON support.
pip install "souldoc[all]"
foreignObject to preserve rich, editable content.PyPI package analytics
Loading the latest archived statistics...
Build documents once
Start with the small core, add the renderers your project needs, and let every format consume the same calculated document.