Skip to content

Releases: py-pdf/fpdf2

FPDF.bezier() to render quadratic and cubic Bézier curves, and many improvements

04 Oct 12:05
Compare
Choose a tag to compare

Note: a temporary 2.8.0 version was released but then erroneously removed on Pypi.
Versions 2.8.0 & 2.8.1 are exactly the same.

Added

  • support for quadratic and cubic Bézier curves with FPDF.bezier() - thanks to @awmc000
  • support for escape character for markers in markdown text issue #1215
  • Wrapping words on spaces now considers all common space symbols in addition to regular spaces (' '), addressing issues with word-wrapping for languages like Thai, as per #1190 and #1191.
  • Templates can now be also defined in JSON files.
  • support to optionally set wrapmode in templates (default "WORD" can optionally be set to "CHAR" to support wrapping on characters for scripts like Chinese or Japanese) - cf. #1159 - thanks to @carlhiggs
  • documentation on how to use fpdf2 with Rough.js: link to docs
  • documentation on how to use fpdf2 with gunicorn: link to docs
  • new translation of the tutorial in Türkçe, thanks to @Natgho: Türkçe
  • feature to identify the Unicode script of the input text and break it into fragments when different scripts are used, improving text shaping results
  • FPDF.image(): now handles keep_aspect_ratio in combination with an enum value provided to x
  • FPDF.write_html(): now supports CSS page breaks properties : documentation
  • FPDF.write_html(): new optional font_family parameter to set the default font family
  • FPDF.write_html(): spacing before lists can now be adjusted via the tag_styles attribute - thanks to @lcgeneralprojects
  • file names are mentioned in errors when fpdf2 fails to parse a SVG image

Fixed

Removed

  • support for Python 3.7, that reached end-of-life in 2023
  • an obscure and undocumented feature of FPDF.write_html(), which used to magically pass instance attributes as arguments.

Deprecated

  • fpdf.TitleStyle has been renamed into fpdf.TextStyle
  • FPDF.write_html(): tag_indents introduced in the last version - Now the indentation can be provided through the tag_styles parameter, using the .l_margin of TextStyle instances

Changed

  • FPDF.local_context() used to treat font_size as a value in points. Now this is the role of font_size_pt, whereas font_size allows to set the font size into chosen document units (specified with FPDF(unit=)) - MR: #1207
  • FPDF.circle() : the previous r parameter, that in fact defined the diameter, has been replaced by a new radius paremeter. The x & y parameters now define the circle center, instead of its top-left corner as it used to be - issue #1245
  • FPDF.table() now raises an error when a single row is too high to be rendered on a single page
  • FPDF.write_html(): indentation of HTML elements can now be non-integer (float), and is now independent of font size and bullet strings.
  • improved performance of font glyph selection by using functools cache
  • Clarified usage of the style attribute in FPDF.add_font()

Improvements on `table()` and `write_html()`, and several bugfixes.

17 May 16:26
1e366a4
Compare
Choose a tag to compare

Added

  • new optional parameter repeat_headings for FPDF.table() that indicates whether to print table headings on every page
  • support for overriding paragraph direction on bidirectional text
  • new optional li_prefix_color parameter for FPDF.write_html()
  • support for start & type attributes of <ol> tags, and type attribute of <ul> tags, when using FPDF.write_html()
  • FPDF.write_html() now accepts a tag_styles parameter to control the font, color & size of HTML elements: <a>, <blockquote>, <li>...
  • FPDF.write_html() now accepts a tag_indents parameter to control, for example, the indent of <blockquote> elements
  • FPDF.write_html() now honors line-height attributes on <ol> & <li> elements, or the same CSS property in style attributes on those tags
  • allow to define custom cell_fill_mode logic for tables: Set cells background - documentation section. Also added 2 new values: TableCellFillMode.EVEN_ROWS & TableCellFillMode.EVEN_COLUMNS: documentation

Fixed

  • a bug when rendering vector images with dashed lines that caused a warning message in Adobe Acrobat Reader
  • ordering RTL fragments on bidirectional texts
  • fixed type hint of member level in class OutlineSection from str to int.
  • SVG clipping paths being incorrectly painted - cf. issue #1147]
  • new translation of the tutorial in Polski - thanks to @DarekRepos

Changed

  • improved the performance of FPDF.start_section() - cf. issue #1092

Deprecated

  • The dd_tag_indent & li_tag_indent parameters of FPDF.write_html() are replaced by the new tag_indents generic parameter.
  • The heading_sizes & pre_code_font parameters of FPDF.write_html() are replaced by the new tag_styles generic parameter.

Table improvements, bidirectional text support, support for <path> in SVG and several bug fixes

10 Feb 04:34
1bd4548
Compare
Choose a tag to compare

Added

  • support for <path> elements in SVG <clipPath> elements
  • support for bidirectional text shaping - thanks to @andersonhc
  • documentation on how to combine fpdf2 with mistletoe in order to generate PDF documents from Markdown (link)
  • tutorial in Dutch: Handleiding - thanks to @Polderrider
  • support for Table cells that span multiple rows via the rowspan attribute, which can be combined with colspan - thanks to @mjasperse
  • TableSpan.COL and TableSpan.ROW enums that can be used as placeholder table entries to identify span extents - thanks to @mjasperse

Fixed

  • when adding a link on a table cell, an extra link was added erroneously on the left. Moreover, now FPDF._disable_writing() properly disable link writing.
  • FPDF.write_html() now handles linking directly to other pages - thanks to @mjasperse
  • non-bold TitleStyle is now rendered as non-bold even when the current font is bold
  • calling .table() inside the render_toc_function
  • using .set_text_shaping(True) & .offset_rendering()
  • fixed gutter handing when a pagebreak occurs within a table with header rows - thanks to @mjasperse
  • fixed handling of border=0 in HTML table - thanks to @mjasperse
  • FPDF.write_html() now properly honors align= attributes in <th> tags
  • fixed problem using bold italic standard fonts in markdown - thanks to @Alan-Collins

Changed

  • refactored FPDF.multi_cell() to generate fewer PDF component objects - thanks to @mjasperse
  • outer table borders are now drawn continuously for nonzero gutter_width/gutter_height, with spacing applied inside the border similar to HTML tables - thanks to @mjasperse - cf. #1071
  • removed the requirement that all rows in a Table have the same number of columns - thanks to @mjasperse

Deprecated

  • font aliases (ArialHelvetica, CourierNewCourer, TimesNewRomanTimes). They will be removed in a later release.

Support for Images and Clipping Paths in SVG files - Python 3.12 Support - Several Bugfixes

10 Dec 13:40
652a517
Compare
Choose a tag to compare

Added

  • Basic support for <image> elements in SVG vector graphics inserted
  • SVG importing now supports clipping paths, and <defs> tags anywhere in the SVG file - thanks to @afriedman412 - cf. #968
  • FPDF.fonts.FontFace: Now has a static combine method that allows overriding a default FontFace (e.g. for specific cells in a table). Unspecified properties of the override FontFace retain the values of the default - thanks to @TedBrookings - cf. #979
  • TextColumns() can now have images inserted (both raster and vector) - thanks to @gmischler
  • TextColumns() can now advance to the next column with the new new_column() method or a FORM_FEED character (\u000c) in the text - thanks to @gmischler
  • Added support for Free Text annotations: documentation - thanks to @MarekT0v - cf. #1039
  • Tutorial in Dutch: Handleiding - thanks to @Polderrider
  • Python 3.12 is now officially supported

Fixed

  • Links over text in tables were broken in release 2.7.6, this is now fixed
  • FPDF.set_font_color() raised a TypeError when used in tables
  • FPDF.image(x=Align.C) used to fail for SVG images - fixed thanks to @gmischler - cf. #1003
  • Previously set dash patterns were not transferred correctly to new pages - fixed thanks to @gmischler - cf. #993
  • Inserted Vector images used to ignore the keep_aspect_ratio argument.
  • FPDF.write_html() now properly honor the current text font color when styling table cells
  • FPDF.write_html() delays unescaping data so as not to confuse entity names as nested tags
  • FPDF.multi_cell() has improved handling of new_x and new_y when padding is non-zero.
  • FPDF.multi_cell(fill=True) now avoids overlapping multiline strings when padding is non-zero.

Changed

  • the public .images, .icc_profiles & .image_filter attributes of FPDF instances have been moved inside a nested FPDF.image_cache attribute. Similarly, the FPDF.preload_image() is now a function in the fpdf.image_parsing module: documentation
  • the fpdf.svg module now produces WARNING log messages for unsupported SVG tags & attributes.
    If those logs annoy you, you can suppress them: logging.getLogger("fpdf.svg").propagate = False
  • FPDF.table(): If cell styles are provided for cells in heading rows, combine the cell style as an override with the overall heading style.

Improvements to FPDF.table() - Text regions layout management - several bugfixes

11 Oct 15:08
fd00303
Compare
Choose a tag to compare

This release is the first performed from the @py-pdf GitHub org, where fpdf2 migrated.
This release also marks the arrival of two new maintainers: Georg Mischler (@gmischler) and Anderson Herzogenrath da Costa (@andersonhc).

Added

Changed

  • The formatting output by write_html() has changed in some aspects. Vertical spacing around headings and paragraphs may be slightly different, and elements at the top of the page don't have any extra spacing above anymore.
  • FPDF.table(): If the height of a row is governed by an image, then the default vertical alignment of the other cells is "center". This was "top".
  • variable-width non-breaking space (NBSP) support issue #834
    This change was made for consistency between row-height governed by text or images. The old behaviour can be enforced using the new vertical alignment parameter.

Fixed

  • In multi_cells and table cells with horizontal padding, the text was not given quite enough space.
  • write_html() can now handle formatting tags within paragraphs without adding extra line breaks (except in table cells for now).
  • the font size in HTML <pre> and <code> tags is not fixed to 11 pica anymore, but adapts to the preceding text.
  • FPDF.ln(), when called before any text has been written, will now use the current font height instead of doing nothing - cf. issue #937
  • FPDF.image(), when provided a BytesIO instance, does not close it anymore - cf. issue #881
  • Invalid characters were being generated when a string contains parentheses - cf. issue #884
  • Frozen Glyph dataclass was causing problems for FPDFRecorder with TTF fonts - cf. issue #890
  • Edge case when parsing a Markdown link followed by a newline - cf. issue #916, and when bold/italics/underline markers are repeated
  • Zoom not set correctly when a numeric value was set in set_display_mode() - cf. issue #926
  • FPDF.table(): images no longer overlap with cell borders - cf. issue #892
  • Encryption of strings containing non-latin characters - cf. issue #933
  • Handling of fragments with zero-length - cf. issue #902

Deprecated

  • to improve naming consistency, the txt parameters of FPDF.cell(), FPDF.multi_cell(), FPDF.text() & FPDF.write() have been renamed to text

Text shaping using Harfbuzz - New mirror() method - New AES-256 encryption - Several bugfixes

04 Aug 15:55
Compare
Choose a tag to compare

Added

Fixed

Deprecated

  • the center optional parameter of FPDF.cell() is no more deprecated, as it allows for horizontal positioning, which is different from text alignment control with align="C"

Images can now be embedded as CMYK - Docs for using Pygal & FastAPI - Various bugfixes

28 Apr 16:01
Compare
Choose a tag to compare

Added

Fixed

  • FPDF.table(): images no more overflow cells
  • FPDF.table(): text overflow in the last cell of the header row is now properly handled
  • FPDF.table(): when align="RIGHT" is provided, the page right margin is now properly taken in consideration

Changed

  • FPDF.write_html() does not render the top row as a header, in bold with a line below, when no <th> are used, in order to be more backward-compatible with earlier versions of fpdf2 - cf. #740

Deprecated

  • the split_only optional parameter of FPDF.multi_cell(), which is replaced by two new distincts optional parameters: dry_run & output

Removing debug print() statement

03 Apr 12:14
Compare
Choose a tag to compare

Fixed

  • removed a debug print() statement left in output.py:OutputProducer._add_fonts() 🤦‍♂️ - A rule was also added to .pre-commit-config.yaml to avoid this to happen again.

SVG & table() bugfixes

03 Apr 09:59
Compare
Choose a tag to compare

Fixed

  • custom fonts can be used with FPDF.table() without triggering a TypeError: cannot pickle 'dict_keys' object - thanks @aeris07 for the bug report
  • the SVG parser now accepts <rect> with width / height defined as percents

New methods table() and set_fallback_fonts() - keep_aspect_ratio - ICC Profiles

27 Mar 15:43
Compare
Choose a tag to compare

Added

Fixed

  • outlines & hyperlinks were not working on encrypted files - thanks to @andersonhc
  • a bug was introduced in the previous release (2.6.1): FPDF.set_link() could not update links generated with add_link()
  • unicode (non limited to ASCII) text can now be provided as metadata #685
  • all TitleStyle constructor parameters are now effectively optional
  • memory usage was reduced by 10 MiB in some cases, thanks to a small optimization in using fonttools

Changed

  • FPDF.write_html() now uses the new FPDF.table() method to render <table> tags. As a consequence, vertical space before <table> tags has sometimes been reduced.
  • vector images parsing is now more robust: fpdf2 can now embed SVG files without viewPort or no height / width
  • bitonal images are now encoded using CCITTFaxDecode, reducing their size in the PDF document - thanks to @eroux
  • when possible, JPG and group4 encoded TIFFs are now embedded directly without recompression - thanks to @eroux

Removed

  • FPDF.write_html() now uses the new FPDF.table() method to render <table> tags. As a consequence, it does not support the height attribute defined on <td> / <th> tags anymore, nor height / width attributes defined on <img> tags inside cells, nor width attributes defined on <thead> / <tfoot> tags.