Sphinx SVG to PDF or PNG Converter Extension
This extension converts SVG images to PDF or PNG when Sphinx builders do not natively support SVG images (e.g., LaTeX). It leverages external tools like Inkscape, rsvg-convert (from libRSVG), or CairoSVG for the conversion. The library is currently at version 2.1.0 and is actively maintained with updates released as needed to support Sphinx versions and conversion tools.
Warnings
- gotcha This library acts as a wrapper around external tools (Inkscape, rsvg-convert, or CairoSVG). You must install these underlying conversion tools and ensure they are accessible in your system's PATH, or configure their paths in `conf.py`. The `[CairoSVG]` extra will install the Python `cairosvg` package, but `cairosvg` itself has system dependencies (like `libcairo`) that are not automatically handled by `pip`.
- gotcha The choice of conversion backend (Inkscape, rsvg-convert, or CairoSVG) is determined by which specific extension you add to your `conf.py`'s `extensions` list (e.g., `sphinxcontrib.inkscapeconverter`, `sphinxcontrib.rsvgconverter`, `sphinxcontrib.cairosvgconverter`). There is no single `sphinxcontrib.svg2pdfconverter` entry to configure the backend.
- breaking Support for converting SVG images to PNG (in addition to PDF) was added in version 2.0.0. If your project requires PNG output, ensure you are using `sphinxcontrib-svg2pdfconverter` version 2.0.0 or newer.
- gotcha When using the `rsvgconverter` backend, specifying `rsvg_converter_format = 'pdf1.5'` in `conf.py` is recommended. This format often generates fewer warnings and offers better compatibility with LaTeX backends, especially with newer versions of `rsvg-convert`.
Install
-
pip install sphinxcontrib-svg2pdfconverter -
pip install sphinxcontrib-svg2pdfconverter[CairoSVG]
Imports
- Extension Activation
extensions = ['sphinxcontrib.inkscapeconverter'] # or .rsvgconverter, .cairosvgconverter
Quickstart
# conf.py
import os
import sys
sys.path.insert(0, os.path.abspath('.'))
project = 'My Sphinx Project'
copyright = '2026, Your Name'
author = 'Your Name'
extensions = [
'sphinx.ext.autodoc',
'sphinx.ext.napoleon',
'sphinxcontrib.cairosvgconverter', # Choose your backend: inkscapeconverter, rsvgconverter, or cairosvgconverter
]
# Example: Configure path for Inkscape if not in PATH (uncomment and adjust as needed)
# inkscape_converter_bin = '/usr/local/bin/inkscape'
# Example: Configure rsvg-convert (uncomment and adjust as needed)
# rsvg_converter_bin = '/usr/bin/rsvg-convert'
# rsvg_converter_format = 'pdf1.5' # Recommended for LaTeX compatibility