Metadata-Version: 2.4
Name: turbo-html2pdf
Version: 0.1.3
Classifier: Programming Language :: Rust
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: Implementation :: CPython
Classifier: Topic :: Multimedia :: Graphics
Classifier: Topic :: Text Processing :: Markup :: HTML
Classifier: License :: OSI Approved :: MIT License
Requires-Dist: pytest>=7 ; extra == 'test'
Provides-Extra: test
Summary: Native HTML/CSS-to-PDF engine with a Jinja-compatible templating DSL (PyO3 binding over the turbo-pdf Rust core).
Keywords: pdf,html,css,template,jinja,rust
Author: turbo-pdf contributors
License: MIT
Requires-Python: >=3.8
Description-Content-Type: text/markdown; charset=UTF-8; variant=GFM
Project-URL: Repository, https://github.com/miaskiewicz/turbo-html2pdf

# turbo-html2pdf (Python)

Native HTML/CSS-to-PDF engine with a Jinja-compatible templating DSL. PyO3
binding over the `turbo-pdf` Rust core; mirrors the Node `turbo-html2pdf`
package 1:1.

```python
import turbo_html2pdf as t

# Compile once, render many times.
prog = t.compile("<p>Hello {{ data.name }}</p>")
pdf = prog.render(data={"name": "world"})       # -> bytes, starts with b"%PDF"

# Warm fonts once, reuse the handle across renders.
fonts = t.Fonts.load([open(p, "rb").read() for p in font_paths])
pdf = prog.render(
    data={"name": "world"},
    css="body { font-family: font0 }",
    fonts=fonts,
)

# One-shot: compile + render in a single call.
pdf = t.render("<p>{{ data.x }}</p>", data={"x": 1})

# Inspect non-fatal lints + page count.
pdf, diagnostics, page_count = prog.render_full(data={"name": "world"})
```

Fatal compile/render faults raise `TurboPdfError` carrying `.code` (a stable
string such as `"TemplateSyntax"`) and `.span` (`{"line", "col", "byte_offset"}`).
Non-fatal lints are returned by `render_full`, never raised.

## API

| Surface | Signature |
| --- | --- |
| `compile(template_html, opts=None)` | `-> Program` |
| `Program.render(data=None, css="", fonts=None, images=None, meta=None, now=None)` | `-> bytes` |
| `Program.render_full(...)` | `-> (bytes, list[dict], int)` |
| `Program.has_header()` / `Program.has_footer()` | `-> bool` |
| `render(template_html, ...)` | one-shot `-> bytes` |
| `Fonts.load([bytes, ...])` | warm registry `-> Fonts` |

## Building from source

```sh
pip install maturin
maturin develop --manifest-path crates/turbo-pdf-py/Cargo.toml
python -m pytest crates/turbo-pdf-py/tests
```

