pdfΒ·je [π PDFΒ·yuh] (noun) Dutch for 'small PDF'
Write beautiful PDFs in declarative Python.
(Currently in development. Leave a βοΈ on GitHub if you're interested how this develops!)
What makes pdfje stand out from the other PDF writers? Here are some of the highlights:
In most PDF writers, you create empty objects and
then mutate them with methods like addText()
,
all while changing the state with methods like setFont()
.
Pdfje is different. You describe the document you want to write,
and pdfje takes care of the details. No state to manage, no mutations.
This makes your code easier to reuse and reason about.
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
See the roadmap for supported features.
Legibility counts. Good typography is a key part of that. Pdfje supports several features to make your documents look great:
- Visually pleasing linebreaks, using the same basic principles as LaTeX
- Automatic kerning using available font metrics
- Avoiding widows and orphans by moving lines between columns or pages.
The PDF format 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 pdfje pure-Python, it allows you to install only the dependencies you need.
pip install pdfje # no dependencies
pip install pdfje[fonts, hyphens] # embedded fonts and improved hyphenation
Pdfje has basic functionality, but is not yet feature-complete. Until the 1.0 version, the API may change with minor releases.
Features:
β = implemented, π§ = may be planned, β = not planned
- Typesetting
- β Automatic kerning
- β Wrapping text into lines, columns, and pages
- β Page sizes
- β Centering text
- β Justification
- β Hyphenation
- β Move lines between columns/pages to avoid widows/orphans
- β Tex-style line breaking
- π§ Headings (which stick to their paragraphs)
- π§ Indentation
- π§ Keeping layout elements together
- π§ Loosening paragraphs to avoid orphans/widows
- π§ Broader unicode support in text wrapping
- 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
- π§ Bullet/numbered lists
- π§ Inline markup with Markdown (Commonmark/MyST)
- β Emoji
- β Tables of contents
- β Forms
- β Annotations
Pdfje follows semantic versioning. Until the 1.0 version, the API may change with minor releases. Breaking changes will be announced in the changelog. Since the API is fully typed, your typechecker and/or IDE will help you adjust to any API changes.
This library is licensed under the terms of the MIT license.
It also includes short scripts from other projects (see pdfje/vendor
),
which are either also MIT licensed, or in the public domain.
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
pdfje is inspired by the following projects. If you're looking for a PDF writer, you may want to check them out as well: