Skip to content

Releases: py-pdf/fpdf2

HTMLMixin not needed anymore - more HTML tags supported - demonstration Jupyter notebook

20 Nov 17:51
Compare
Choose a tag to compare

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

Support for subscript & superscript - set_page_background - embed_file - set_char_spacing

08 Sep 12:05
Compare
Choose a tag to compare

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

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

PDF document signing - greek tutorial - better SVG image parsing

16 Aug 12:57
Compare
Choose a tag to compare

Added

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

Parsing of SVG files with CSS styling, FPDF.rect() with round_corners, FPDF.star()

17 Jun 08:54
Compare
Choose a tag to compare

Added

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

New .page_mode & .viewer_preferences properties

05 May 14:29
Compare
Choose a tag to compare

Added

  • new FPDF.page_mode property, allowing to display a PDF 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

New image clipping methods

02 May 22:05
Compare
Choose a tag to compare

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.

new_x/new_y, highlight annotations, text_mode & blend_mode

13 Apr 21:22
Compare
Choose a tag to compare

Added

  • new parameters new_x and new_y for cell() and multi_cell(), replacing ln=0, thanks to @gmischler
  • new add_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.

Displaying deprecation warnings

DeprecationWarnings 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).

Support for soft-hyphens - image() can now insert .svg files - deprecating font caching

07 Mar 09:59
Compare
Choose a tag to compare

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.

New vector drawing API & SVG embedding

22 Jan 17:42
Compare
Choose a tag to compare

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

HACKTOBERFEST! Detect oversized images, new methods to draw arcs & regular polygons, improved documentation

16 Nov 14:27
Compare
Choose a tag to compare

Added

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()