Skip to main content

svg2pdf-py

Fast, accurate SVG → PDF conversion for Python, powered by the svg2pdf Rust crate from Typst. Built with PyO3 and Maturin.

Unlike rasterization-based approaches, svg2pdf-py produces true vector PDFs — text stays selectable, paths stay sharp at any scale, and custom fonts are fully embedded.


Features

  • Vector-accurate SVG → PDF (no rasterization)
  • Custom font support via usvg / fontdb
  • Batch conversion for multi-page PDFs
  • Exposes raw PDF chunks for embedding into existing documents
  • Pre-built wheels for Windows, Linux, and macOS (Python ≥ 3.9)

Installation

pip install svg2pdf-py

Quick Start

import svg2pdf_py

# Load custom fonts
db = svg2pdf_py.FontDatabase()
db.load_font_file("/path/to/MyFont.ttf")
db.load_font_file("/path/to/MyFont-Bold.ttf")

# Convert SVG string → PDF bytes
svg_str = open("diagram.svg", encoding="utf-8").read()
pdf_bytes = svg2pdf_py.svg_to_pdf(svg_str, db)

open("diagram.pdf", "wb").write(pdf_bytes)

API

FontDatabase

Manages fonts used during SVG rendering.

# Empty database
db = svg2pdf_py.FontDatabase()

# Pre-loaded with system fonts
db = svg2pdf_py.FontDatabase.system()

db.load_font_file("/path/to/font.ttf")   # load a single font file
db.load_fonts_dir("/path/to/fonts/")     # load all fonts in a directory
db.load_system_fonts()                   # add system fonts to existing db
len(db)                                  # number of loaded font faces

ConversionOptions

Controls PDF output quality.

opts = svg2pdf_py.ConversionOptions(
    compress=True,      # deflate-compress streams (default: True)
    raster_scale=1.0,   # scale factor for rasterized elements (default: 1.0)
    embed_text=True,    # embed text as real PDF text, not outlines (default: True)
)

svg_to_pdf

Convert a single SVG string to a standalone PDF.

pdf_bytes: bytes = svg2pdf_py.svg_to_pdf(
    svg_str,   # str — SVG content
    db,        # FontDatabase
    options,   # ConversionOptions (optional)
)

svg_to_chunk

Convert a single SVG string to a raw PDF chunk (XObject), suitable for embedding into an existing PDF document.

chunk_bytes: bytes = svg2pdf_py.svg_to_chunk(
    svg_str,
    db,
    options,   # optional
)

svg_pages_to_pdfs

Convert a list of SVG strings to individual PDF byte strings — one per page.

pages: list[bytes] = svg2pdf_py.svg_pages_to_pdfs(
    svg_strings,   # list[str]
    db,
    options,       # optional
)

Multi-Page Example

Combine multiple SVGs into a single PDF using PyMuPDF:

import svg2pdf_py
import pymupdf

db = svg2pdf_py.FontDatabase()
db.load_fonts_dir("/path/to/fonts/")

svg_pages = [open(f"page{i}.svg").read() for i in range(1, 5)]
pdf_pages = svg2pdf_py.svg_pages_to_pdfs(svg_pages, db)

doc = pymupdf.open()
for pdf_bytes in pdf_pages:
    part = pymupdf.open("pdf", pdf_bytes)
    doc.insert_pdf(part)
    part.close()

doc.save("output.pdf", garbage=4, deflate=True)
doc.close()

Credits

This package is a thin PyO3 binding over the excellent svg2pdf crate by Typst, which in turn uses usvg for SVG parsing and fontdb for font resolution.


License

MIT

Metadata

Release files for svg2pdf-py 1.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distributions (wheels)

Table of built distributions (wheels) for svg2pdf-py 1.1.0
File Interpreter ABI Platform Actions
svg2pdf_py-1.1.0-cp311-abi3-win_amd64.whl CPython 3.11 abi3 Windows x86-64 Details for svg2pdf_py-1.1.0-cp311-abi3-win_amd64.whl
svg2pdf_py-1.1.0-cp311-abi3-manylinux_2_35_x86_64.whl CPython 3.11 abi3 Linux glibc 2.35+ x86-64 Details for svg2pdf_py-1.1.0-cp311-abi3-manylinux_2_35_x86_64.whl
svg2pdf_py-1.1.0-cp311-abi3-macosx_11_0_arm64.whl CPython 3.11 abi3 macOS 11.0+ ARM64 Details for svg2pdf_py-1.1.0-cp311-abi3-macosx_11_0_arm64.whl

Total release size: 6.9 MB

Release files / svg2pdf_py-1.1.0-cp311-abi3-win_amd64.whl

Download URL svg2pdf_py-1.1.0-cp311-abi3-win_amd64.whl
Size 2.1 MB
Tags CPython 3.11 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
8c9052bd9d87a41f7ed2360e83a323b14219f08ef83dcf252f551f65da74e050
BLAKE2b-256 checksum
How to use checksums
b660f9278872b37ffcfce77c3749ba9fb3440f4a20638e8a38423c73d854d617
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jun 2, 2026.

Transparency log

Release files / svg2pdf_py-1.1.0-cp311-abi3-manylinux_2_35_x86_64.whl

Download URL svg2pdf_py-1.1.0-cp311-abi3-manylinux_2_35_x86_64.whl
Size 2.6 MB
Tags CPython 3.11 Linux glibc 2.35+ x86-64 abi3
SHA-256 checksum
How to use checksums
1329c86f89cc845db6a9b878fd928465452b366324b6c2d935cfa4e8e7c5eadc
BLAKE2b-256 checksum
How to use checksums
fba65dd93e50dcb755af2ac037ffbc065f87f7f1cbe8d9af6300a1956c989a74
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jun 2, 2026.

Transparency log

Release files / svg2pdf_py-1.1.0-cp311-abi3-macosx_11_0_arm64.whl

Download URL svg2pdf_py-1.1.0-cp311-abi3-macosx_11_0_arm64.whl
Size 2.2 MB
Tags CPython 3.11 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
cb020fc65ad57682f18c27a76549a7740ae135a73f8317a012abc17a9313bc00
BLAKE2b-256 checksum
How to use checksums
84604f695218d7a3f77ed593197fcc43dfdbcd22b3bab74b2f1f3ca1f6988119
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jun 2, 2026.

Transparency log

Security for svg2pdf-py 1.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 3 files in this release have been uploaded with provenance metadata.

Select from 3 files

Attestation for svg2pdf_py-1.1.0-cp311-abi3-win_amd64.whl

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jun 2, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

1.1.0 This release

3 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page