Metadata-Version: 2.4
Name: veloxpdf
Version: 0.1.0
Summary: Python bindings for the VeloxPDF HTML-to-PDF renderer
License-Expression: Apache-2.0
Project-URL: Repository, https://github.com/saadzimat430/veloxpdf
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
Dynamic: license-file

# VeloxPDF for Python

VeloxPDF renders HTML and CSS to PDF in-process. The Python package uses
`ctypes` and supports Python 3.10 or later with no Python runtime dependencies.
Release wheels bundle the native renderer for Windows x86-64, macOS x86-64
and ARM64, and glibc Linux x86-64 and ARM64.

## Install

Download the `veloxpdf-python-<target>` artifact for your platform from a
**Release artifacts** workflow run, extract it, and install its wheel.

```sh
python -m pip install /path/to/veloxpdf-0.1.0-py3-none-win_amd64.whl
```

Linux wheels encode their minimum glibc version in the `manylinux` tag. Once a
version is published to PyPI, install it with `python -m pip install veloxpdf`.

## Render a PDF

```python
from pathlib import Path
from veloxpdf import render_html

pdf = render_html("<!doctype html><h1>Bonjour!</h1><p>Hello from Python.</p>")
Path("hello.pdf").write_bytes(pdf)
```

`render_html` accepts a `str` or UTF-8 `bytes` and returns the complete PDF
as `bytes`. With no options, the renderer follows CSS `@page` rules and uses
its native defaults for unset settings. Pass a `PdfOptions` instance to set
the page size, orientation, and margin explicitly.

```python
from pathlib import Path
from veloxpdf import Orientation, PageSize, PdfEngine, PdfOptions

pages = PdfOptions(PageSize.LETTER, Orientation.LANDSCAPE, margin_mm=18)
with PdfEngine(max_input_bytes=1_048_576, max_pages=20) as engine:
    pdf = engine.render("<h1>Quarterly report</h1>", pages)
    Path("report.pdf").write_bytes(pdf)
```

Reuse one engine across requests and threads. Call `close()` or use a
`with` block to wait for active renders and release the engine. Use
`PdfOptions(PageSize.CUSTOM, custom_width_mm=120, custom_height_mm=180)`
for custom paper sizes. Pass font paths or bytes with
`PdfEngine(fonts=[Path("ReportSans.ttf")])` to register fonts at creation.
Rendering uses the native offline resource policy. Native loading and
rendering errors raise `VeloxPdfError`, whose `status` holds the C ABI status
when available.

## Develop from a checkout

Run these commands from the repository root. On macOS, use
`libveloxpdf_native.dylib` in the library path.

```sh
cargo build --release --locked -p veloxpdf-ffi
export VELOXPDF_LIBRARY="$PWD/target/release/libveloxpdf_native.so"
python -m pip install -e . pypdf
python -m unittest discover -s bindings/python/tests -v
```

```powershell
cargo build --release --locked -p veloxpdf-ffi
$env:VELOXPDF_LIBRARY = (Resolve-Path target/release/veloxpdf_native.dll).Path
python -m pip install -e . pypdf
python -m unittest discover -s bindings/python/tests -v
```

`pypdf` is used by the tests. Set `VELOXPDF_LIBRARY` to use a trusted local
ABI v1 library with any installation. The override takes precedence over
the bundled library.
