๐ŸŒท pdfjeยถ

https://img.shields.io/pypi/v/pdfje.svg?style=flat-square&color=blue https://img.shields.io/pypi/pyversions/pdfje.svg?style=flat-square https://img.shields.io/pypi/l/pdfje.svg?style=flat-square&color=blue https://img.shields.io/badge/mypy-strict-forestgreen?style=flat-square https://img.shields.io/badge/coverage-99%25-forestgreen?style=flat-square https://img.shields.io/github/actions/workflow/status/ariebovenberg/pdfje/tests.yml?branch=main&style=flat-square https://img.shields.io/readthedocs/pdfje.svg?style=flat-square

pdfยทje [๐Ÿ”‰ PDFยทyuh] (noun) Dutch for โ€˜small PDFโ€™

Write beautiful PDFs in declarative Python.

(Currently in active development. Leave a โญ๏ธ on GitHub if youโ€™re interested how this develops!)

Featuresยถ

What makes pdfje stand out from the other PDF writers? Here are some of the highlights:

๐Ÿงฉ Declarative APIยถ

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.

๐Ÿ“– Decent typographyยถ

Legibility counts. Good typography is a key part of that. Pdfje supports several features to make your documents look great:

Sample document with two columns of text

๐ŸŽˆ Small footprintยถ

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

Roadmapยถ

Pdfje 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

    • โœ… 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

Versioning and compatibility policyยถ

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.

Licenseยถ

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.

Contributingยถ

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

Acknowledgementsยถ

pdfje is inspired by the following projects. If youโ€™re looking for a PDF writer, you may want to check them out as well:

Contentsยถ

Indices and tablesยถ