fpdf2 latest new features

I wrote my latest post on fpdf2 almost a year ago. As we just released a new version, v2.7.3, this is the time to mention some recent additions to this library! 😊

This article will present some of the major features introduced between v2.5.3 & v2.7.3 of fpdf2:

Tables

One major addition of v2.7.0 of fpdf2 has the new method .table(), that now makes very easy the generation of tables in PDF documents.

We documented how to use this method in a dedicated documentation page: https://pyfpdf.github.io/fpdf2/Tables.html

Here is some snippet of demo code:

from fpdf import FPDF

TABLE_DATA = (
    ("First name", "Last name", "Age", "City"),
    ...
)

pdf = FPDF()
pdf.add_page()
pdf.set_font("Helvetica", size=16)
with pdf.table(borders_layout="MINIMAL",
               col_widths=(30, 30, 10, 30),
               cell_fill_color=200,  # grey scale
               cell_fill_mode="ROWS",
               text_align="CENTER") as table:
    for data_row in TABLE_DATA:
        row = table.row()
        for datum in data_row:
            row.cell(datum)
pdf.output("table-demo.pdf")

And the result: Sample table rendered in a PDF document

Images & shapes

There has been several new features related to images:

  • FPDF.image() has two new optional parameters: align="C" to horizontally an image on a page, and keep_aspect_ratio which allows to preserve an image ratio. Related documentation section: fitting an image inside a rectangle.

  • thanks to a contribution by @eroux in PR #709, ICC Profiles of images inserted by FPDF.image() are now extracted an inserted in the PDF document: doc.

  • rectangles drawn with FPDF.rect() can now have rounded corners using the new round_corners parameter. Check the documentation for examples: Shapes: rectangles with round corners.

  • we documentated on how to control transparency of overlapping text, shapes and images through stroke_opacity & fill_opacity: documentation.

Example overlapping objects with transparency

Fonts & text

Usage example of subscript, superscript, nominator and denominator

Signing & encrypting documents

Annotations

Ink annotation example

Documentation & translated tutorials

A demonstration Jupyter notebook has been created: tutorial/notebook.ipynb

New translations of our tutorial were also provided:

What's coming next?

We have several enhancement proposals open (and mostly "up-for-grabs"), and also an handful of good first issues dedicated to developpers would like to start contributing to fpdf2 with a relatively easy task.

Among major projects, two contributors made very interesting & ambitious suggestions:

Finally, I am seriously considering to move the fpdf2 project to the @py-pdf GitHub organization, in order to share ownership of several PDF-related Python libraries with other maintainers and join forces! You can track this migration project and share your feedback in this GitHub discussion: https://github.com/PyFPDF/fpdf2/discussions/752.

As always, I would be happy to receive your comments below 😊