Prince: convert HTML with CSS to PDF. Bundles the Prince engine - no separate install required.
Project description
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") # Prince 17+
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/"))
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 inargs, e.g.args=("--javascript",). Returns the output path, or the PDF asbyteswhenoutputis 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 a bundled Prince 17 or later (pip install --pre prince-pdfwhile 17 is in pre-release); on older enginesmarkdown_to_pdfraises an error saying exactly that.- Failures raise
PrinceErrorcarrying.returncode, raw.stderr, and.messages— the engine's diagnostics parsed intoMessage(severity, location, text)tuples. Engine warnings during successful conversions are emitted on the"prince_pdf"logger. prince_pdf.run(*args, **kwargs)— a thinsubprocess.run()wrapper for raw engine access. It does not apply the error handling or diagnostic parsing thatconvert()provides: nonzero exits do not raise (passcheck=TrueforCalledProcessError), 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 asrun()).prince_pdf.executable()— path of the bundled engine binary.prince_pdf.version()— the engine's version string.prince_pdf.license()— the default license-file location inside the bundle (preferPRINCE_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) orapk 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. - Diagnosing failures:
PrinceError.stderrcarries the engine's warnings and errors; add--verbose(or-oplus--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).
Maintainer documentation — how wheels are built, verified, and released — is in RELEASING.md.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distributions
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file prince_pdf-16.2.0.post1-py3-none-win_arm64.whl.
File metadata
- Download URL: prince_pdf-16.2.0.post1-py3-none-win_arm64.whl
- Upload date:
- Size: 12.2 MB
- Tags: Python 3, Windows ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fb40ae967046d1ab897590d369a61e28efec451aa74a2bfe837e338b1e342d15
|
|
| MD5 |
fece0f53f4c9c07f62f1525bdcd6ee84
|
|
| BLAKE2b-256 |
8d9581d2b2cfdeecaeb08035fe2db62b89c5081e9d51900a1076d36773b83fcb
|
Provenance
The following attestation bundles were made for prince_pdf-16.2.0.post1-py3-none-win_arm64.whl:
Publisher:
wheels.yml on yeslogic/prince-python
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
prince_pdf-16.2.0.post1-py3-none-win_arm64.whl -
Subject digest:
fb40ae967046d1ab897590d369a61e28efec451aa74a2bfe837e338b1e342d15 - Sigstore transparency entry: 2167062026
- Sigstore integration time:
-
Permalink:
yeslogic/prince-python@c958a430fbff8de34360ea07f34fe447887c7b00 -
Branch / Tag:
refs/tags/v16.2.0.post1 - Owner: https://github.com/yeslogic
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
wheels.yml@c958a430fbff8de34360ea07f34fe447887c7b00 -
Trigger Event:
push
-
Statement type:
File details
Details for the file prince_pdf-16.2.0.post1-py3-none-win_amd64.whl.
File metadata
- Download URL: prince_pdf-16.2.0.post1-py3-none-win_amd64.whl
- Upload date:
- Size: 13.9 MB
- Tags: Python 3, Windows x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8aa6ab0eb7693548d147153795c17f50419944177dc635f9b01d0edae1f6fbf5
|
|
| MD5 |
87ca437b99de5f7e1fc5b9642281b47d
|
|
| BLAKE2b-256 |
3f5ece0c5c02fe6031d9533e806013c64f197707e1232152d5acfe1d62036f82
|
Provenance
The following attestation bundles were made for prince_pdf-16.2.0.post1-py3-none-win_amd64.whl:
Publisher:
wheels.yml on yeslogic/prince-python
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
prince_pdf-16.2.0.post1-py3-none-win_amd64.whl -
Subject digest:
8aa6ab0eb7693548d147153795c17f50419944177dc635f9b01d0edae1f6fbf5 - Sigstore transparency entry: 2167062001
- Sigstore integration time:
-
Permalink:
yeslogic/prince-python@c958a430fbff8de34360ea07f34fe447887c7b00 -
Branch / Tag:
refs/tags/v16.2.0.post1 - Owner: https://github.com/yeslogic
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
wheels.yml@c958a430fbff8de34360ea07f34fe447887c7b00 -
Trigger Event:
push
-
Statement type:
File details
Details for the file prince_pdf-16.2.0.post1-py3-none-musllinux_1_2_aarch64.whl.
File metadata
- Download URL: prince_pdf-16.2.0.post1-py3-none-musllinux_1_2_aarch64.whl
- Upload date:
- Size: 14.1 MB
- Tags: Python 3, musllinux: musl 1.2+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
07d7d752c31a747808c5af19ab6051fb429fb403f1e0332ec50329366e3e12a0
|
|
| MD5 |
4b4168d19f495933a90b004f335c17aa
|
|
| BLAKE2b-256 |
5e8f512243b30c9c5127f4db88d74bf8e29a4e30b60c2a228a80beccf5a8d680
|
Provenance
The following attestation bundles were made for prince_pdf-16.2.0.post1-py3-none-musllinux_1_2_aarch64.whl:
Publisher:
wheels.yml on yeslogic/prince-python
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
prince_pdf-16.2.0.post1-py3-none-musllinux_1_2_aarch64.whl -
Subject digest:
07d7d752c31a747808c5af19ab6051fb429fb403f1e0332ec50329366e3e12a0 - Sigstore transparency entry: 2167062014
- Sigstore integration time:
-
Permalink:
yeslogic/prince-python@c958a430fbff8de34360ea07f34fe447887c7b00 -
Branch / Tag:
refs/tags/v16.2.0.post1 - Owner: https://github.com/yeslogic
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
wheels.yml@c958a430fbff8de34360ea07f34fe447887c7b00 -
Trigger Event:
push
-
Statement type:
File details
Details for the file prince_pdf-16.2.0.post1-py3-none-manylinux_2_25_aarch64.whl.
File metadata
- Download URL: prince_pdf-16.2.0.post1-py3-none-manylinux_2_25_aarch64.whl
- Upload date:
- Size: 13.3 MB
- Tags: Python 3, manylinux: glibc 2.25+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
693084876236d43543149b090971958b757497b6af4eaf44b6f03014b02796d2
|
|
| MD5 |
05036c78dc44f20a9c798fcc5753c1b1
|
|
| BLAKE2b-256 |
0d4d393afce44002de62bd5b2f3460483ef3bee845bd6b1e7293aa99cfd2275f
|
Provenance
The following attestation bundles were made for prince_pdf-16.2.0.post1-py3-none-manylinux_2_25_aarch64.whl:
Publisher:
wheels.yml on yeslogic/prince-python
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
prince_pdf-16.2.0.post1-py3-none-manylinux_2_25_aarch64.whl -
Subject digest:
693084876236d43543149b090971958b757497b6af4eaf44b6f03014b02796d2 - Sigstore transparency entry: 2167062020
- Sigstore integration time:
-
Permalink:
yeslogic/prince-python@c958a430fbff8de34360ea07f34fe447887c7b00 -
Branch / Tag:
refs/tags/v16.2.0.post1 - Owner: https://github.com/yeslogic
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
wheels.yml@c958a430fbff8de34360ea07f34fe447887c7b00 -
Trigger Event:
push
-
Statement type:
File details
Details for the file prince_pdf-16.2.0.post1-py3-none-manylinux_2_17_x86_64.whl.
File metadata
- Download URL: prince_pdf-16.2.0.post1-py3-none-manylinux_2_17_x86_64.whl
- Upload date:
- Size: 14.6 MB
- Tags: Python 3, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b73b322fdc11541762aa3fda5c0231b9e5f5b97896adc611dc35c9474ecae590
|
|
| MD5 |
45deed0ed5c765ffbca1fefaaa7a3a50
|
|
| BLAKE2b-256 |
a31e5bb1a8b4c8143d8c76664eaab4a2e6eec26de319f546e2b5873e672fe21b
|
Provenance
The following attestation bundles were made for prince_pdf-16.2.0.post1-py3-none-manylinux_2_17_x86_64.whl:
Publisher:
wheels.yml on yeslogic/prince-python
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
prince_pdf-16.2.0.post1-py3-none-manylinux_2_17_x86_64.whl -
Subject digest:
b73b322fdc11541762aa3fda5c0231b9e5f5b97896adc611dc35c9474ecae590 - Sigstore transparency entry: 2167061997
- Sigstore integration time:
-
Permalink:
yeslogic/prince-python@c958a430fbff8de34360ea07f34fe447887c7b00 -
Branch / Tag:
refs/tags/v16.2.0.post1 - Owner: https://github.com/yeslogic
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
wheels.yml@c958a430fbff8de34360ea07f34fe447887c7b00 -
Trigger Event:
push
-
Statement type:
File details
Details for the file prince_pdf-16.2.0.post1-py3-none-macosx_10_13_universal2.whl.
File metadata
- Download URL: prince_pdf-16.2.0.post1-py3-none-macosx_10_13_universal2.whl
- Upload date:
- Size: 25.0 MB
- Tags: Python 3, macOS 10.13+ universal2 (ARM64, x86-64)
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
66bbd7404c5b3a27cf2813030c8249aceca2971eefcd0d34fd9c912537da9207
|
|
| MD5 |
32a21b870bd264cba6eda4ad14ea004b
|
|
| BLAKE2b-256 |
e90d741bc79b6323da29354ceecd866cfebc179904ab637fd3fd82f08885aa75
|
Provenance
The following attestation bundles were made for prince_pdf-16.2.0.post1-py3-none-macosx_10_13_universal2.whl:
Publisher:
wheels.yml on yeslogic/prince-python
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
prince_pdf-16.2.0.post1-py3-none-macosx_10_13_universal2.whl -
Subject digest:
66bbd7404c5b3a27cf2813030c8249aceca2971eefcd0d34fd9c912537da9207 - Sigstore transparency entry: 2167062007
- Sigstore integration time:
-
Permalink:
yeslogic/prince-python@c958a430fbff8de34360ea07f34fe447887c7b00 -
Branch / Tag:
refs/tags/v16.2.0.post1 - Owner: https://github.com/yeslogic
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
wheels.yml@c958a430fbff8de34360ea07f34fe447887c7b00 -
Trigger Event:
push
-
Statement type: