Skip to main content

prince-pdf

Python packaging of Prince, the HTML-with-CSS to PDF engine. The wheel bundles the Prince engine for the current platform: no separate installation, and neither installing the package nor launching the engine downloads anything. (Prince will access the network only if a document being converted references remote resources such as images or stylesheets.)

pip install prince-pdf
import prince_pdf

prince_pdf.convert("document.html", "document.pdf")

pdf_bytes = prince_pdf.html_to_pdf("<h1>Hello</h1>")    # in-memory

pdf_bytes = prince_pdf.markdown_to_pdf("# Hello")

The package also puts prince on PATH, so the full command-line interface works as documented:

prince document.html -o document.pdf

python -m prince_pdf also works anywhere the package is importable, even when the script directory is not on PATH.

Names

One package, three names: install it as prince-pdf, import it as prince_pdf, run it as prince. Note that pip install prince installs an unrelated statistics library, not this package.

Files vs. strings

convert() always interprets strings as filesystem paths, never as document content. To convert an HTML string, use html_to_pdf().

The *_to_pdf functions pipe the document through the engine's standard input, so the engine never sees a filename: relative URLs in the document are resolved against the current working directory, not against wherever the content originally came from. If a string derived from /tmp/report/index.html references images/chart.svg, pass the original location as a base URL:

prince_pdf.html_to_pdf(html, args=("--baseurl", "/tmp/report/"))

Using a separately installed Prince

The bundled engine is the default, but the wrapper can drive an existing Prince installation instead — a licensed system install, or a newer engine. Set the PRINCE_PATH environment variable to the installation's prince executable (the command you would normally run — pointing it at a directory is rejected with an error), or select one per call:

prince_pdf.convert("doc.html", "doc.pdf", executable="/usr/bin/prince")

The per-call executable argument overrides PRINCE_PATH, which overrides the bundled engine. External engines run without --prefix, so the installation locates its own style sheets, fonts, and license. PRINCE_LICENSE_FILE is honored either way.

Python API

The package ships inline type annotations (py.typed).

  • prince_pdf.convert(inputs, output=None, args=()) — convert one or more files (HTML, XML, SVG; Markdown with Prince 17+; a list is merged into one PDF), with the format detected from each file. Extra command-line options go in args as a sequence of individual argument tokens — args=("--baseurl", "https://x.example/"), never a shell string like "--baseurl https://x.example/". Returns the output path, or the PDF as bytes when output is None.
  • prince_pdf.html_to_pdf(html, output=None, args=()), prince_pdf.markdown_to_pdf(markdown, ...), prince_pdf.xml_to_pdf(xml, ...) — convert a document given as a string or bytes, without temporary files. Markdown input requires Prince 17 or later.
  • Failures raise PrinceError carrying .returncode, raw .stderr, and .messages — the engine's diagnostics parsed into Message(severity, location, text) tuples. During successful conversions, engine warnings are emitted on the "prince_pdf" logger; pass on_message= to receive every diagnostic yourself instead (an exception from the callback aborts the call).
  • prince_pdf.run(*args, **kwargs) — a thin subprocess.run() wrapper for raw engine access. It does not apply the error handling or diagnostic parsing that convert() provides: nonzero exits do not raise (pass check=True for CalledProcessError), and output is not captured unless requested.
  • prince_pdf.command(*args) — the argv list that would be run, for use with external process tooling (same caveats as run()).
  • prince_pdf.executable() — path of the engine that will be invoked (the bundled engine, unless PRINCE_PATH selects another).
  • prince_pdf.version() — the engine's version string.
  • prince_pdf.license() — the default license-file location inside the bundle (prefer PRINCE_LICENSE_FILE, which survives reinstalls).

Licensing

Prince may be used without a purchased license under the conditions in the included Prince License Agreement (LICENSE-Prince.txt); unlicensed output carries a watermark on the first page. Commercial use requires an appropriate license from YesLogic. Point the engine at your license file with the PRINCE_LICENSE_FILE environment variable (preferred — it survives reinstalls), or install it at the path returned by prince_pdf.license(). The Python wrapper code itself is MIT-licensed (LICENSE).

Troubleshooting

  • Missing or wrong fonts in minimal containers: the wheel bundles the engine but uses the system's fonts. Install some, e.g. apt-get install fonts-dejavu fontconfig (Debian/Ubuntu) or apk add fontconfig ttf-dejavu (Alpine).
  • libfontconfig.so.1: cannot open shared object file (Linux x86-64): install the system fontconfig library, e.g. apt-get install libfontconfig1 — installing fonts as above also provides it.
  • Watermark on the first page: expected without a license — see Licensing above.
  • Documents referencing remote resources: fetching http(s) images or stylesheets requires network access at conversion time; self-contained local files need none.
  • No matching distribution found for prince-pdf: this means pip couldn't reach or match, not necessarily that the package doesn't exist. In sandboxed environments, check proxy settings (pip config list, HTTP_PROXY/NO_PROXY) — the registry may only be reachable through the sandbox's egress proxy. It can also mean no wheel exists for the platform (see Supported platforms below).
  • Diagnosing failures: PrinceError.stderr carries the engine's warnings and errors; add --verbose (or -o plus --log=FILE) for more detail.

Supported platforms

Linux x86-64 and ARM64 (glibc), musl/Alpine ARM64, macOS 10.13+ (universal), Windows x64 and ARM64. On Linux x86-64 the engine additionally needs the system fontconfig library — in minimal containers, apt-get install libfontconfig1 (it usually arrives with fonts anyway).

Python 3.8 or later.


Maintainer documentation — how wheels are built, verified, and released — is in RELEASING.md. A Node.js equivalent of this package is available on npm under the same name.

Metadata

Release files for prince-pdf 17.0.0.post2

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 prince-pdf 17.0.0.post2
File
prince_pdf-17.0.0.post2-py3-none-win_arm64.whl Python 3 none Windows ARM64 Details
prince_pdf-17.0.0.post2-py3-none-win_amd64.whl Python 3 none Windows x86-64 Details
prince_pdf-17.0.0.post2-py3-none-musllinux_1_2_aarch64.whl Python 3 none Linux musl 1.2+ ARM64 Details
prince_pdf-17.0.0.post2-py3-none-manylinux_2_25_x86_64.whl Python 3 none Linux glibc 2.25+ x86-64 Details
prince_pdf-17.0.0.post2-py3-none-manylinux_2_25_aarch64.whl Python 3 none Linux glibc 2.25+ ARM64 Details
prince_pdf-17.0.0.post2-py3-none-macosx_10_13_universal2.whl Python 3 none macOS 10.13+ universal2 (ARM64, x86-64) Details

Total release size: 106.8 MB

Release files / prince_pdf-17.0.0.post2-py3-none-win_arm64.whl

Download URL prince_pdf-17.0.0.post2-py3-none-win_arm64.whl
Size 13.7 MB
Tags Python 3 Windows ARM64
SHA-256 checksum
How to use checksums
3bf687e985d856155421618d32783308b35b05bf63501c759c9d258876dd8462
BLAKE2b-256 checksum
How to use checksums
c5d91f834df9aaecdfac06197c44151dc71ca697fe147681017cb7435099fcdb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Oct 3, 2026.

Transparency log

Release files / prince_pdf-17.0.0.post2-py3-none-win_amd64.whl

Download URL prince_pdf-17.0.0.post2-py3-none-win_amd64.whl
Size 15.4 MB
Tags Python 3 Windows x86-64
SHA-256 checksum
How to use checksums
8d139e9c2c848944bf8abfc1712a3a04cdb481d57242925cbffc45d535c254cb
BLAKE2b-256 checksum
How to use checksums
3dec265cb086d5cae8f21a903edc62bd3f9202431c4b4e72f3889cb5ce9ead84
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Oct 3, 2026.

Transparency log

Release files / prince_pdf-17.0.0.post2-py3-none-musllinux_1_2_aarch64.whl

Download URL prince_pdf-17.0.0.post2-py3-none-musllinux_1_2_aarch64.whl
Size 16.6 MB
Tags Linux musl 1.2+ ARM64 Python 3
SHA-256 checksum
How to use checksums
d80d3f4314f495f2982305fb1029743438a9aafe3d8e551d736e9b70288d07e3
BLAKE2b-256 checksum
How to use checksums
86782f9ec0d5b3f9010b6c8e08695842eb619213ab942370570715b2e60fc1fc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Oct 3, 2026.

Transparency log

Release files / prince_pdf-17.0.0.post2-py3-none-manylinux_2_25_x86_64.whl

Download URL prince_pdf-17.0.0.post2-py3-none-manylinux_2_25_x86_64.whl
Size 16.4 MB
Tags Linux glibc 2.25+ x86-64 Python 3
SHA-256 checksum
How to use checksums
8ce54bffa13f73ef5f1727b07a6afe34832f3df4613294e530a414cf3ed6f899
BLAKE2b-256 checksum
How to use checksums
158680546b16f5dee4868432f85982f23c57540233e5053e3a0abfdeb93a27f8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Oct 3, 2026.

Transparency log

Release files / prince_pdf-17.0.0.post2-py3-none-manylinux_2_25_aarch64.whl

Download URL prince_pdf-17.0.0.post2-py3-none-manylinux_2_25_aarch64.whl
Size 15.7 MB
Tags Linux glibc 2.25+ ARM64 Python 3
SHA-256 checksum
How to use checksums
570ccba627c0996bfc5534a11c33200dc4e78181d3c82f5cbe0e213a9d86ae0d
BLAKE2b-256 checksum
How to use checksums
99e9a8de381db52de16f9d57ccb00dc077c6b19171efed02f437aea7b0744d59
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Oct 3, 2026.

Transparency log

Release files / prince_pdf-17.0.0.post2-py3-none-macosx_10_13_universal2.whl

Download URL prince_pdf-17.0.0.post2-py3-none-macosx_10_13_universal2.whl
Size 28.9 MB
Tags Python 3 macOS 10.13+ universal2 (ARM64, x86-64)
SHA-256 checksum
How to use checksums
6d5b213014f557117a292475c1e14d3189a6ef3c0f27796e52e48c1c1a88204d
BLAKE2b-256 checksum
How to use checksums
485d1489442079b806c052df0188014747c714829ab91bde911b7bc7cdddf9af
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Oct 3, 2026.

Transparency log
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