Skip to content

Latest commit

 

History

History
679 lines (624 loc) · 63.6 KB

CHANGELOG.md

File metadata and controls

679 lines (624 loc) · 63.6 KB

Changelog

All notable changes to this project will be documented in this file.

The format is based on Keep a Changelog and this project adheres to Semantic Versioning, and PEP 440.

Displaying deprecation warnings

DeprecationWarning messages are not displayed by Python by default.

Hence, every time you use a newer version of fpdf2, we strongly encourage you to execute your scripts with the -Wd option (cf. documentation) in order to get warned about deprecated features used in your code.

This can also be enabled programmatically with warnings.simplefilter('default', DeprecationWarning).

[2.7.10] - Not released yet

Added

  • 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
  • support for quadratic and cubic Bézier curves with FPDF.bezier() - thanks to @awmc000
  • 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
  • file names are mentioned in errors when fpdf2 fails to parse a SVG image
  • FPDF.write_html(): now supports CSS page breaks properties : documentation
  • FPDF.write_html(): spacing before lists can now be adjusted via the HTML2FPDF.list_vertical_margin attribute - thanks to @lcgeneralprojects

Fixed

  • FPDF.local_context() used to leak styling during page breaks, when rendering footer() & header()
  • fpdf.drawing.DeviceCMYK objects can now be passed to FPDF.set_draw_color(), FPDF.set_fill_color() and FPDF.set_text_color() without raising a ValueError: documentation.
  • FPDF.write_html(): fixing rendering of <hr> tags, that do not trigger a page break anymore
  • FPDF.write_html(): fixed automatic page break when an image does not have enough vertical space to be rendered on a page
  • individual /Resources directories are now properly created for each document page. This change ensures better compliance with the PDF specification but results in a slight increase in the size of PDF documents. You can still use the old behavior by setting FPDF().single_resources_object = True
  • line size calculation for fragments when text shaping is used
  • FPDF.write_html(): fixed incoherent indentation of long <ul> list entries - cf. issue #1073 - thanks to @lcgeneralprojects
  • default values for top_margin and bottom_margin in HTML2FPDF._new_paragraph() calls are now correctly converted into chosen document units.

Removed

Changed

  • FPDF.table() now raises an error when a single row is too high to be rendered on a single page
  • FPDF.write_html(): tag_indents can now be non-integer. Indentation of HTML elements is now independent of font size and bullet strings.

[2.7.9] - 2024-05-17

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() - thanks to @dmail00 - 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.

[2.7.8] - 2024-02-09

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)
  • 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, CourierNewCourier, TimesNewRomanTimes). They will be removed in a later release.

[2.7.7] - 2023-12-10

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.

[2.7.6] - 2023-10-11

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

  • The new experimental method text_columns() allows to render text within a single or multiple columns, including height balancing: documentation - thanks to @gmischler
  • FPDF.table(): Now supports padding in cells : documentation - thanks to @RubendeBruin
  • FPDF.table(): Now supports vertical alignment in cells : documentation - thanks to @RubendeBruin
  • FPDF.table(): Now supports outer border width for rendering the outer border of the table with a different line-width - thanks to @RubendeBruin
  • FPDF.table(): Now supports multiple heading rows : documentation - thanks to @SandraFer
  • FPDF.write_html() now supports heading colors defined as attributes (e.g. <h2 color="#00ff00">...) - thanks to @Lucas-C
  • documentation on how to use livereload to enable a "watch" mode with PDF generation: Combine with livereload - thanks to @Lucas-C

Changed

  • FPDF.write_html(): the formatting output 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

  • FPDF.table() & FPDF.multi_cell(): when some horizontal padding was set, the text was not given quite enough space - thanks to @gmischler
  • FPDF.write_html() can now handle formatting tags within paragraphs without adding extra line breaks (except in table cells for now) - thanks to @gmischler
  • FPDF.write_html(): the font size in HTML <pre> and <code> tags is not fixed to 11 pica anymore, but adapts to the preceding text - thanks to @gmischler
  • FPDF.ln(), when called before any text has been written, will now use the current font height instead of doing nothing - thanks to @gmischler - cf. issue #937
  • FPDF.image(), when provided a BytesIO instance, does not close it anymore - cf. issue #881 - thanks to @Lucas-C
  • Invalid characters were being generated when a string contains parentheses - thanks to @andersonhc - cf. issue #884
  • Frozen Glyph dataclass was causing problems for FPDFRecorder with TTF fonts - thanks to @andersonhc - 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 - thanks to @RubendeBruin - cf. issue #892
  • Encryption of strings containing non-latin characters - thanks to @andersonhc - cf. issue #933
  • Handling of fragments with zero-length - thanks to @SaiHarshaK - 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

[2.7.5] - 2023-08-04

Added

Fixed

  • FPDF.table(): the colspan setting has been fixed - documentation
  • FPDF.image(): allowing images path starting with data to be passed as input
  • text overflow is better handled by FPDF.write() & FPDF.write_html() - cf. issue #847
  • the initial text color is preserved when using FPDF.write_html() - cf. issue #846
  • PDF metadata not encrypted - cf. issue #865
  • handle superscript and subscript correctly when rendering TextLine- thanks to @Tolker-KU - cf. Pull Request #862
  • make sure warnings always point to the users code - cf. Pull request #869

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"

[2.7.4] - 2023-04-28

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

[2.7.3] - 2023-04-03

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.

[2.7.2] - 2023-04-03

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

Added

[2.7.1] - 2023-03-27

Changed

[2.7.0] - 2023-03-27

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.

[2.6.1] - 2023-01-13

Added

  • support for PDF encryption (RC4 and AES-128): documentation page - thanks to @andersonhc
  • FPDF.skew() - New method: documentation page - thanks to @erap129
  • ensured support for Python 3.11
  • FPDF.image(): the x parameter now accepts a value of "C" / Align.C / "R" / Align.R to horizontally position the image centered or aligned right
  • FPDF.image(): dimensions can now be provided to set the intrinsic image width & height before storing it in the PDF
  • FPDF.cell() & FPDF.multi_cell(): support for []() hyperlinks when markdown=True
  • FPDF.write_html(): support for line-height attribute of paragraph (<p>) - thanks to @Bubbu0129
  • documentation on useful tools to manipulate PDFs
  • show a warning if the font being used doesn't have all the necessary glyphs for the text - thanks to @andersonhc

Changed

  • FPDF.add_link() creates a link to the current page by default, and now accepts optional parameters: x, y, page & zoom. Hence calling set_link() is not needed anymore after creating a link with add_link().
  • FPDF.write_html() now generates warnings for unclosed HTML tags, unless warn_on_tags_not_matching=False is set

Fixed

  • FPDF.write_html(): a ValueError: Incoherent hierarchy could be raised with some headings hierarchy
  • FPDF.write_html(): <img> without height attribute overlaps with the following content #632 - thanks to @Bubbu0129
  • FPDF.image(): performance issue with adding large images with FlateDecode image filter #644 - thanks to @Markovvn1
  • FPDF.add_font(): fix support for upper case font file name #638 - thanks to @CY-Qiu

[2.6.0] - 2022-11-20

Added

Deprecated

  • HTMLMixin is deprecated, and not needed anymore: the write_html() method is now natively available in the FPDF class - thanks to @yk-jp

Removed

  • open() & close() methods, that were only used internally and should never have been called by end-user code
  • FPDF.state, which was an instance of the DocumentState enum, and has been replaced by moving the final rendering logic into a new fpdf.output module

Fixed

  • after an "empty" cell(), ln() applied a line height of zero #601
  • when using multi_cell() with max_line_height to render multiline text, the last line is now rendered like all the others
  • templates don't leak graphics state changes to their surroundings anymore; #570
  • automatic page break is never performed on an empty page (when the Y position is at the top margin)
  • fixed insert_toc_placeholder() usage with footer() and {{nb}}; #548
  • the SVG parser now accepts stroke-width attribute values with an explicit unit, thanks to @gmischler; #526
  • the SVG parser now accepts absolute units for width and height attributes, thanks to @darioackermann; #555
  • write_html() method now correctly handles whitespace when parsing HTML. <pre></pre> blocks still maintain spaces, tabs and line breaks.

Changed

  • the first parameter of FPDF.add_font() is now optional: if it is not provided, the base name of the fname font path is used to define the font family. Hence pdf.add_font(fname="fonts/NotoSansArabic.ttf") will define a font named NotoSansArabic.
  • the output of embed_file() is now a PDFEmbeddedFile, not a string, but the internal file name can be retrieved through its .basename property
  • forbid use of get_y() & local_context() inside unbreakable() as it is currently not supported; #557
  • fontTools minimal version requirement set to 4.34.0; #524

[2.5.7] - 2022-09-08

Added

Changed

  • HTML headings are now rendered with an additional leading of 20% the font size above and below them; #520
  • fpdf2 now uses fontTools to read and embed fonts in the PDF, thanks to @gmischler and @RedShy
  • since the fonttools library offers similar functionality, the dependency to "svg.path" is gone again, thanks to @gmischler; #525

Fixed

  • text following a HTML heading can't overlap with that heading anymore, thanks to @gmischler
  • arc() not longer renders artefacts at intersection point, thanks to @Jmillan-Dev; #488
  • write_html():
    • <em> & <strong> HTML tags are now properly supported - they were ignored previously; #498
    • bgcolor is now properly supported in <table> tags; #512
  • the CreationDate of PDFs & embedded files now includes the system timezone

[2.5.6] - 2022-08-16

Added

  • new methods to allow signing PDF documents: link to docs
  • support for colors defined with the rgb() syntax in SVG images - cf. #480
  • New translation of the tutorial in Ελληνικά, thanks to @sokratisvas

Changed

  • an /ID is now inserted in the trailer dictionary of all PDF documents generated. This ID can be controlled through the new file_id() method.
  • the svg.path package was added as a dependency to better parse SVG images

Fixed

  • font_stretching doesn't make text spill out of multi_cell() and write() boundaries anymore, thanks to @gmischler
  • local_context() now always restores the correct font settings after finishing, thanks to @gmischler
  • properly parsing single-digits arguments in SVG paths - cf. #450
  • document outline encoding: it was found to be broken when using a thai font - cf. #458

[2.5.5] - 2022-06-17

Added

  • a new option align="X" to .cell() and .multi_cell() allows to center text around the current x position, thanks to @gmischler
  • allowing to provide an AnnotationName and AnnotationFlags onto text_annotation()
  • allowing correctly parsing of SVG files with CSS styling (style="..." attribute), thanks to @RedShy
  • FPDF.star(): new method added to draw regular stars, thanks to @digidigital and @RedShy
  • FPDF.ink_annotation(): new method added to add path annotations
  • allowing embedding of indexed PNG images without converting them to RGB colorspace, thanks to @RedShy
  • allowing to change appearance of highlight annotations by specifying a TextMarkupType
  • documentation on how to control objects transparency: link to docs
  • documentation on how to create tables and charts using pandas DataFrames: link to docs, thanks to @iwayankurniawan
  • added argument round_corners to FPDF.rect() that allows to draw rectangles with round corners: link to docs - thanks to @gonzalobarbaran

Changed

Fixed

  • support for "x" & "y" attributes in SVG <use> tags - cf. #446
  • CreationDate of PDFs generated, that was broken - cf. #451
  • multi_cell() and write() ignored a trailing newline character in the supplied text since 2.5.1 - fixed thanks to @gmischler

[2.5.4] - 2022-05-05

Added

  • new FPDF.page_mode property, allowing to display a PDF automatically in full screen: link to docs
  • new FPDF.viewer_preferences property: link to docs

Fixed

  • removed a debug print() statement (multi_cell: new_x=... new_y=...) that had been left in multi_cell() method 🤦‍♂️
  • preserved backward compatibility with PyFPDF for passing positional arguments to cell() & multi_cell(), which was broken in 2.5.2

Modified

  • when regular_polygon() is called with style="f", the shape outline is not drawn anymore. Use style="DF" to also draw a line around its perimeter.

Deprecated

  • the fill parameter of the polygon() & polyline() methods have been replaced by a style argument, offering more control

[2.5.3] - 2022-05-03

Added

Modified

  • TextMode, XPos & YPos now inherit from CoerciveEnum and hence can simply be passed as string parameters

Fixed

  • infinite loop when calling .multi_cell() without enough horizontal space - cf. #389

Removed

  • support for .pkl files passed to add_font(). This was deprecated since v2.5.1. As a consequence, fpdf2 no more uses the pickle module \o/

[2.5.2] - 2022-04-13

Added

  • new parameters new_x and new_y for cell() and multi_cell(), replacing ln=0, thanks to @gmischler
  • new highlight() method to insert highlight annotations: documentation
  • new offset_rendering() method: documentation
  • new .text_mode property: documentation
  • the page structure of the documentation has been revised, with a new page about adding text, thanks to @gmischler
  • a warning is now raised if a context manager is used inside an unbreakable() section, which is not supported

Changed

  • local_context() can now "scope" even more properties, like blend_mode: documentation

Fixed

  • No font properties should be leaked anymore after using markdown or in any other situations (cf. #359), thanks to @gmischler
  • If multi_cell(align="J") is given text with multiple paragraphs (text followed by an empty line) at once, it now renders the last line of each paragraph left-aligned, instead of just the very last line (cf. #364), thanks to @gmischler
  • a regression: now again multi_cell() always renders a cell, even if txt is an empty string - cf. #349
  • a bug with string width calculation when Markdown is enabled - cf. #351
  • a few bugs when parsing some SVG files - cf. #356, #358 & #376
  • a bug when using multi_cell(..., split_only=True) inside an unbreakable section - cf. #359

Deprecated

  • The parameter ln to cell() and multi_cell() is now deprecated: use new_x and new_y instead.
  • The parameter center to cell() is now deprecated, use align="C" instead.

[2.5.1] - 2022-03-07

Added

Changed

  • write() now supports soft hyphen characters, thanks to @gmischler
  • fname is now a required parameter for FPDF.add_font()
  • image() method now insert .svg images as PDF paths
  • the defusedxml package was added as dependency in order to make SVG parsing safer
  • log level of _substitute_page_number() has been lowered from INFO to DEBUG

Fixed

  • a bug when rendering Markdown and setting a custom text_color or fill_color
  • a bug in get_string_width() with unicode fonts and Markdown enabled, resulting in calls to cell() / multi_cell() with align="R" to display nothing - thanks @mcerveny for the fix!
  • a bug with incorrect width calculation of markdown text

Deprecated

  • the font caching mechanism, that used the pickle module, has been removed, for security reasons, and because it provided little performance gain, and only for specific use cases - cf. issue #345. That means that the font_cache_dir optional parameter of fpdf.FPDF constructor and the uni optional argument of FPDF.add_font() are deprecated. The fpdf.fpdf.load_cache function has also been removed.

To be extra clear: uni=True can now be removed from all calls to FPDF.add_font(). If the value of the fname argument passed to add_font() ends with .ttf, it is considered a TrueType font.

[2.5.0] - 2022-01-22

Added

Thanks to @torque for contributing this massive new feature:

  • add fpdf.drawing API for composing paths from an arbitrary sequence of lines and curves.
  • add fpdf.svg.convert_svg_to_drawing function to support converting basic scalable vector graphics (SVG) images to PDF paths.

Fixed

  • will_page_break() & accept_page_break are not invoked anymore during a call to multi_cell(split_only=True)
  • Unicode characters in headings are now properly displayed in the table of content, cf. #320 - thanks @lcomrade

[2.4.6] - 2021-11-16

Added

  • New FPDF.pages_count property, thanks to @paulacampigotto

  • Temporary changes to graphics state variables are now possible using with FPDF.local_context():, thanks to @gmischler

  • a mechanism to detect & downscale oversized images, cf. documentation. Feedbacks on this new feature are welcome!

  • New set_dash_pattern(), which works with all lines and curves, thanks to @gmischler.

  • Templates now support drawing ellipses, thanks to @gmischler

  • New documentation on how to display equations, using Google Charts or matplotlib: Maths

  • The whole documentation can now be downloaded as a PDF: fpdf2-manual.pdf

  • New sections have been added to the tutorial, thanks to @portfedh:

    1. Creating Tables
    2. Creating links and mixing text styles
  • New translation of the tutorial in Hindi, thanks to @Mridulbirla13: हिंदी संस्करण; Deutsch, thanks to @digidigital; and Italian thanks to @xit4; Русский thanks to @AABur; and português thanks to @fuscati; français, thanks to @Tititesouris

  • While images transparency is still handled by default through the use of SMask, this can be disabled by setting pdf.allow_images_transparency = False in order to allow compliance with PDF/A-1

  • FPDF.arc: new method added. It enables to draw arcs in a PDF document.

  • FPDF.solid_arc: new method added. It enables to draw solid arcs in a PDF document. A solid arc combines an arc and a triangle to form a pie slice.

  • FPDF.regular_polygon: new method added, thanks to @bettman-latin

Fixed

  • All graphics state manipulations are now possible within a rotation context, thanks to @gmischler
  • The exception making the "x2" template field optional for barcode elements did not work correctly, fixed by @gmischler
  • It is now possible to get back to a previous page to add more content, e.g. with a 2-column layout, thanks to @paulacampigotto

Changed

  • All template elements now have a transparent default background instead of white, thanks to @gmischler
  • To reduce the size of generated PDFs, no SMask entry is inserted for images that are fully opaque (= with an alpha channel containing only 0xff characters)
  • The rect, ellipse & circle all have a style parameter in common. They now all properly accept a value of "D" and raise a ValueError for invalid values.

Deprecated

  • dashed_line() is now deprecated in favor of set_dash_pattern()

[2.4.5] - 2021-10-03

Fixed

  • ensure support for old field names in Template.code39 for backward compatibility

[2.4.4] - 2021-10-01

Added

  • Template() has gained a more flexible cousin FlexTemplate(), cf. documentation, thanks to @gmischler
  • markdown support in multi_cell(), thanks to Yeshi Namkhai
  • base 64 images can now be provided to FPDF.image, thanks to @MWhatsUp
  • documentation on how to generate datamatrix barcodes using the pystrich lib: documentation section, thanks to @MWhatsUp
  • write_html: headings (<h1>, <h2>...) relative sizes can now be configured through an optional heading_sizes parameter
  • a subclass of HTML2FPDF can now easily be used by setting FPDF.HTML2FPDF_CLASS, cf. documentation

Fixed

  • Template: split_multicell() will not write spurious font data to the target document anymore, thanks to @gmischler
  • Template: rotation now should work correctly in all situations, thanks to @gmischler
  • write_html: headings (<h1>, <h2>...) can now contain non-ASCII characters without triggering a UnicodeEncodeError
  • Template: CSV column types are now safely parsed, thanks to @gmischler
  • cell(..., markdown=True) "leaked" its final style (bold / italics / underline) onto the following cells

Changed

  • write_html: the line height of headings (<h1>, <h2>...) is now properly scaled with its font size
  • some FPDF methods should not be used inside a rotation context, or things can get broken. This is now forbidden: an exception is now raised in those cases.

Deprecated

  • Template: code39 barcode input field names changed from x/y/w/h to x1/y1/y2/size

[2.4.3] - 2021-09-01

Added

  • support for emojis! More precisely unicode characters above 0xFFFF in general, thanks to @moe-25
  • Template can now insert justified text
  • get_scale_factor utility function to obtain FPDF.k without having to create a document
  • convert_unit utility function to convert a number, x,y point, or list of x,y points from one unit to another unit

Changed

  • fpdf.FPDF() constructor now accepts ints or floats as a unit, and raises a ValueError if an invalid unit is provided.

Fixed

  • Template background property is now properly supported - #203 ⚠️ Beware that its default value changed from 0 to 0xffffff, as a value of zero would render the background as black.
  • Template.parse_csv: preserving numeric values when using CSV based templates - #205
  • the code snippet to generate Code 39 barcodes in the documentation was missing the start & end * characters. This has been fixed, and a warning is now triggered by the FPDF.code39 method when those characters are missing.

Fixed

  • Detect missing uni=True when loading cached fonts (page numbering was missing digits)

[2.4.2] - 2021-06-29

Added

  • disable font caching when fpdf.FPDF constructor invoked with font_cache_dir=None, thanks to @moe-25 !
  • FPDF.circle: new method added, thanks to @viraj-shah18 !
  • write_html: support setting HTML font colors by name and short hex codes
  • FPDF.will_page_break utility method to let users know in advance when adding an elemnt will trigger a page break. This can be useful to repeat table headers on each page for exemple, cf. documentation on Tables.
  • FPDF.set_link now support a new optional x parameter to set the horizontal position after following the link

Fixed

  • fixed a bug when fpdf.Template was used to render QRCodes, due to a forced conversion to string (#175)

[2.4.1] - 2021-06-12

Fixed

  • erroneous page breaks occured for full-width / full-height images
  • rendering issue of non-ASCII characaters with unicode fonts

[2.4.0] - 2021-06-11

Changed

  • now fpdf2 uses the newly supported DCTDecode image filter for JPEG images, instead of FlateDecode before, in order to improve the compression ratio without any image quality loss. On test images, this reduced the size of embeded JPEG images by 90%.
  • FPDF.cell: the w (width) parameter becomes optional, with a default value of None, meaning to generate a cell with the size of the text content provided
  • the h (height) parameter of the cell, multi_cell & write methods gets a default value change, None, meaning to use the current font size
  • removed the useless w & h parameters of the FPDF.text_annotation() method

Added

  • new FPDF.add_action() method, documented in the Annotations section
  • FPDF.cell: new optional markdown=True parameter that enables basic Markdown-like styling: **bold**, __italics__, --underlined--
  • FPDF.cell: new optional boolean center parameter that positions the cell horizontally
  • FPDF.set_link: new optional zoom parameter that sets the zoom level after following the link. Currently ignored by Sumatra PDF Reader, but observed by Adobe Acrobat reader.
  • write_html: now support align="justify"
  • new method FPDF.image_filter to control the image filters used for images
  • FPDF.add_page: new optional duration & transition parameters used for presentations (documentation page)
  • extra documentation on how to configure different page formats for specific pages
  • support for Code 39 barcodes in fpdf.template, using type="C39"

Fixed

  • avoid an Undefined font error when using write_html with unicode bold or italics fonts

Deprecated

  • the FPDF.set_doc_option() method is deprecated in favour of just setting the core_fonts_encoding property on an instance of FPDF
  • the fpdf.SYSTEM_TTFONTS configurable module constant is now ignored

[2.3.5] - 2021-05-12

Fixed

  • a bug in the deprecation module that prevented to configure fpdf2 constants at the module level

[2.3.4] - 2021-04-30

Fixed

  • a "fake duplicates" bug when a Pillow.Image.Image was passed to FPDF.image

[2.3.3] - 2021-04-21

Added

  • new features: document outline & table of contents! Check out the new dedicated documentation page for more information
  • new method FPDF.text_annotation to insert... Text Annotations
  • FPDF.image now also accepts an io.BytesIO as input

Fixed

  • write_html: properly handling <img> inside <td> & allowing to center them horizontally

[2.3.2] - 2021-03-27

Added

  • FPDF.set_xmp_metadata
  • made <li> bullets & indentation configurable through class attributes, instance attributes or optional method arguments, cf. test_customize_ul

Fixed

  • FPDF.multi_cell: line wrapping with justified content and unicode fonts, cf. #118
  • FPDF.multi_cell: when ln=3, automatic page breaks now behave correctly at the bottom of pages

[2.3.1] - 2021-02-28

Added

  • FPDF.polyline & FPDF.polygon : new methods added by @uovodikiwi - thanks!
  • FPDF.set_margin : new method to set the document right, left, top & bottom margins to the same value at once
  • FPDF.image now accepts new optional title & alt_text parameters defining the image title and alternative text describing it, for accessibility purposes
  • FPDF.link now honor its alt_text optional parameter and this alternative text describing links is now properly included in the resulting PDF document
  • the document language can be set using FPDF.set_lang

Fixed

  • FPDF.unbreakable so that no extra page jump is performed when FPDF.multi_cell is called inside this context

Deprecated

  • fpdf.FPDF_CACHE_MODE & fpdf.FPDF_CACHE_DIR in favor of a configurable new font_cache_dir optional argument of the fpdf.FPDF constructor

[2.3.0] - 2021-01-29

Many thanks to @eumiro & @fbernhart for their contributions to make fpdf2 code cleaner!

Added

  • FPDF.unbreakable : a new method providing a context-manager in which automatic page breaks are disabled. cf. https://py-pdf.github.io/fpdf2/PageBreaks.html
  • FPDF.epw & FPDF.eph : new @property methods to retrieve the effective page width / height, that is the page width / height minus its horizontal / vertical margins.
  • FPDF.image now accepts also a Pillow.Image.Image as input
  • FPDF.multi_cell parameters evolve in order to generate tables with multiline text in cells:
    • its ln parameter now accepts a value of 3 that sets the new position to the right without altering vertical offset
    • a new optional max_line_height parameter sets a maximum height of each sub-cell generated
  • new documentation pages : how to add content to existing PDFs, HTML, links, tables, text styling & page breaks
  • all PDF samples are now validated using 3 different PDF checkers

Fixed

  • FPDF.alias_nb_pages: fixed this feature that was broken since v2.0.6
  • FPDF.set_font: fixed a bug where calling it several times, with & without the same parameters, prevented strings passed first to the text-rendering methods to be displayed.

Deprecated

  • the dest parameter of FPDF.output method

[2.2.0] - 2021-01-11

Added

  • new unit tests, a code formatter (black) and a linter (pylint) to improve code quality
  • new boolean parameter table_line_separators for write_html & underlying HTML2FPDF constructor

Changed

Removed

  • dropped support for external font definitions in .font Python files, that relied on a call to exec

Deprecated

  • the type parameter of FPDF.image method
  • the infile parameter of Template constructor
  • the dest parameter of Template.render method

[2.1.0] - 2020-12-07

Added

Modified

Deprecated

Fixed

Removed

  • non-necessary dependency on numpy
  • support for Python 2

[2.0.6] - 2020-10-26

Added

  • Python 3.9 is now supported

[2.0.5] - 2020-04-01

Added

  • new specific exceptions: FPDFException & FPDFPageFormatException
  • tests to increase line coverage in image_parsing module
  • a test which uses most of the HTML features

Fixed

  • handling of fonts by the HTML mixin (weight and style) - thanks cgfrost!

[2.0.4] - 2020-03-26

Fixed

  • images centering - thanks cgfrost!
  • added missing import statment for urlopen in image_parsing module
  • changed urlopen import from six library to maintain python2 compatibility

[2.0.3] - 2020-01-03

Added

  • Ability to use a BytesIO buffer directly. This can simplify loading matplotlib plots into the PDF.

Modified

  • load_resource now return argument if type is BytesIO, else load.

[2.0.1] - 2018-11-15

Modified

  • introduced a dependency to numpy to improve performances by replacing pixel regexes in image parsing (s/o @pennersr)

[2.0.0] - 2017-05-04

Added

  • support for more recent Python versions
  • more documentation

Fixed

  • PDF syntax error when version is > 1.3 due to an invalid /Transparency dict

Modified

  • turned accept_page_break into a property
  • unit tests now use the standard unittest lib
  • massive code cleanup using flake8