pdfΒ·je [π PDFΒ·yuh] (noun) Dutch for 'small PDF'
Write beautiful PDFs in declarative Python.
Currently in active development. See the roadmap for supported features. Leave a βοΈ on GitHub if you're interested how this develops!
There are many PDF libraries for Python, but none of them have these features:
In most PDF writers, you first create various empty objects and
then mutate them with methods like addText()
,
all while changing the state of the writer with methods like setFont()
.
Pdf'je is different. You describe the document you want to write,
and the library takes care of the details. No state to manage, no mutations.
This makes your code easier to reuse and reason about.
Legibility counts. And kerning β i.e. adjusting the spacing between letters β is a key part of this. Automatic kerning is supported everywhere, from web browsers to word processors. However, most PDF writers don't support it. By using font metrics to calculate the correct kerning, pdf'je helps you write documents that look great.
PDF supports many features, but most of the time you only need a few. Why install many dependencies β just to write a simple document? Not only is pdf'je pure-Python, it allows you to install only the dependencies you need.
Getting text onto paper is super easy:
from pdfje import Document
Document("OlΓ‘ Mundo!").write("hello.pdf")
See the tutorial for a complete overview of features, including:
- Styling text including font, size, and color
- Automatic layout of text into one or more columns
- Builtin and embedded fonts
- Drawing basic shapes
Pdf'je is still in active development, so it is not yet feature-complete. Until the 1.0 version, the API may change with minor releases.
Features:
β = implemented, π§ = planned, β = not planned
- Typesetting
- β Automatic kerning
- β Wrapping text into lines, columns, and pages
- β Page sizes
- π§ Centering text
- π§ Justification
- π§ Hyphenation
- π§ Avoiding orphaned lines
- Drawing operations
- β Lines
- β Rectangles
- β Circles, ellipses
- π§ Arbitrary paths, fills, and strokes
- Text styling
- β Font and size
- β Embedded fonts
- β Colors
- β Bold, italic
- π§ Underline and strikethrough
- π§ Superscript and subscript
- β Complex fill patterns
- π§ Images
- π§ Bookmarks and links
- π§ Tables
- π§ Inline markup with Markdown (Commonmark/MyST)
- β Emoji
- β Tables of contents
- β Forms
- β Annotations
It's available on PyPI.
pip install pdfje
By default, no additional dependencies are installed.
If you'd like to use custom fonts, you'll need fontTools
,
which is included in the [fonts]
extras:
pip install pdfje[fonts]
This library is licensed under the terms of the MIT license.
It also includes short scripts from other projects (see pdfje/vendor
),
which are also MIT licensed.
Here are some useful tips for developing in the pdfje
codebase itself:
- Install dependencies with
poetry install
. - To write output files during tests, use
pytest --output-path=<outpur-dir>
- To also run more comprehensive but 'slow' tests, use
pytest --runslow
If pdf'je doesn't suit your needs, here are some other options:
- PyFPDF
- ReportLab
- WeasyPrint
- borb
- wkhtmltopdf
- pydyf