Metadata-Version: 2.4
Name: docx-rs-4jy72q
Version: 0.3.7
Classifier: License :: Other/Proprietary License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Rust
Classifier: Operating System :: MacOS
Classifier: Operating System :: POSIX :: Linux
Summary: Fast DOCX-to-PDF rendering with a Rust layout engine that matches LibreOffice
License: Proprietary
Requires-Python: >=3.10
Description-Content-Type: text/markdown; charset=UTF-8; variant=GFM

# docx-rs

Fast DOCX-to-PDF conversion with a Rust layout engine whose output matches
LibreOffice's, without running LibreOffice.

```python
from docx_rs import convert, convert_bytes

convert("document.docx", "document.pdf")
pdf_bytes = convert_bytes(open("document.docx", "rb").read())
```

Conversions release the GIL, so threads convert in parallel.

## Supported documents

The renderer only produces a PDF when it supports everything in the document. A
document using unsupported features raises `docx_rs.UnsupportedDocument`, whose
`findings` list each unsupported construct; it never returns an approximate PDF.
Support currently covers typical generated legal documents: styles, numbering,
tables, sections, headers and footers, fields such as cached tables of contents,
text boxes and images. Use `docx_rs.inspect(path)` to see the eligibility report
without converting.

## Fonts

The package bundles open fonts and substitutes them for common Microsoft fonts:
TeX Gyre Termes for Times New Roman, Bonum for Bookman Old Style, Carlito for
Calibri/Aptos/Aptos Display, Caladea for Cambria,
Liberation Sans and Mono for Arial and Courier New, OpenSymbol for Symbol and
DejaVu Sans for Segoe UI Symbol, and explicit Linux Libertine G fallback for
qualified uncovered scalars. Version 3 (`debian-bookworm-open-v3`) adds TeX Gyre Pagella for Palatino Linotype, EB Garamond for Garamond
and Gelasio for Georgia. Version 4 (`debian-bookworm-open-v4`, the bundled
default) adds TeX Gyre Schola for Century Schoolbook and Century. All mappings
are explicitly chosen; the v2 mappings are
independently qualified against LibreOffice, while the v3 and v4 additions are visual
substitutes checked on representative documents (EB Garamond is not
metric-compatible with Garamond, so pagination differs from Word). Each font keeps its own licence; see
`docx_rs/fonts/licenses/`. A custom font profile can be passed as
`font_profile=` (a profile JSON path or `docx_rs.FontProfile.load(path)`).


Two bundled presets are verified against LibreOffice using the same font files.
`docx_rs.bundled_profiles()` lists their names and descriptions. `default` keeps
LibreOffice-matching open substitutes. `tnr-spacing` uses the same substitutes,
with Times New Roman and Times mapped to Termes TNR Spacing for Times New Roman
line spacing and pagination, and Palatino Linotype, Bookman Old Style, Cambria,
Georgia, Garamond, Century Schoolbook and Century mapped to derived spacing faces that carry the replaced
font's line height:

```python
import docx_rs

pdf = docx_rs.convert_bytes(data, font_profile=docx_rs.bundled_profile("tnr-spacing"))
```

Profiles are cached per name and shared safely across threads. Termes TNR Spacing
is derived from TeX Gyre Termes under the GUST Font License: only vertical metrics
are changed, and the faces are renamed; glyphs and widths remain unchanged.
`tools/derive_fonts.py` reproduces the faces, whose SHA-256 hashes are pinned in
`fixtures/fonts/debian-bookworm-open-v2-tnr-spacing.json`. It approximates Times
New Roman pagination; slight glyph-width differences can still change line breaks.
`make bundled-fonts` produces both relative-path profiles and their fonts; fontTools
is a build-time dependency in the `fonts` uv group, not a wheel dependency.

