pypi / fpdf2
fpdf2
What changed in fpdf2 2, from its official release notes, upgrade guides and advisories. Sources checked 2026-11-30.
24 breaking1 security29 new APIs and options1 performance14 behavior and defaults88 fixes and other
See which of these apply to your code, ranked, in your agent:
npx @unstale/cli initfpdf2 2157 changes
Breaking changes 24
Repeated flags no longer change unrelated bits; flags are combined with bitwise OR.
The dependency was removed; SVG parsing uses standard-library ElementTree and Expat amplification limits, and bounded internal entities are accepted.
Construction and add_page reject page formats with zero or negative width or height.
Accepts empty byte content and rejects simultaneous path and byte sources even when bytes are empty.
An empty coords sequence now raises a clear ValueError.
numSides below 1 raises a clear ValueError instead of silently writing a path with no points.
Negative margins raise ValueError instead of placing page breaks below the page edge.
Negative or non-numeric zoom values raise FPDFException instead of writing an invalid zoom or failing later.
Negative line widths raise ValueError instead of writing a width disallowed by the PDF specification.
label_start below 1 raises ValueError instead of writing an invalid PDF start value.
Zero or negative stretching raises ValueError instead of breaking text layout.
corners below 1 raise a clear ValueError instead of a ZeroDivisionError or drawing nothing.
Content inside style and script elements is no longer written into the document as text.
Nested tables in table cells raise a descriptive NotImplementedError instead of a bare AssertionError.
Hex strings containing non-hexadecimal characters now raise a clear ValueError.
An index not returned by FPDF.add_link now raises a clear ValueError instead of an assertion or KeyError.
Out-of-range color components are reported as given rather than normalized.
A zero width or height disables rendering instead of using viewport dimensions.
Booleans in arrays and dictionaries serialize as lowercase true and false, None in arrays as null, and filtering empty dictionary fields preserves False and numeric zero.
A custom height passed in a text region is now applied to the line it terminates, rather than the first line of the following paragraph.
Rejects SVG <use> cycles and excessive nested expansion to prevent resource exhaustion in FPDF.image().
The deprecated uni parameter was removed.
The deprecated dest parameter was removed.
Changed
accept_page_breakinto a property.
Security 1
fpdf2 implicitly loads external URLs and local image paths when rendering attacker-controlled content
New APIs and options 29
Create colored and uncolored tiling patterns, including SVG pattern elements and pattern fills and strokes on referenced use shapes.
Supports type="none" to render list items without markers.
SVG <image> tags now support transform, style, opacity, and preserveAspectRatio="none".
Adds an align parameter to control horizontal alignment of page-number substitution text inside reserved alias space.
Adds an appearance parameter accepting FileAttachmentAppearance.HIDDEN to hide the annotation's default icon while keeping the embedded file reachable.
Adds support for page number alias substitution with bidirectional and RTL text shaping.
Adds configurable SVG complexity limits when rendering SVG images.
Adds support for keeping aspect ratio for images in templates.
Adds basic support for SVG <switch> elements in the SVG parser.
Adds basic support for SVG <symbol> elements in the SVG parser.
Adds TTC/OTC face selection through the collection_font_number parameter.
Adds support for embedding CID-keyed CFF fonts.
Adds support for EBDT/EBLC bitmap fonts.
Adds a context manager for applying geometric transformations to the current graphics state.
Graphics state snapshots now use a dataclass, providing clearer usage and stronger typing.
SVG rendering now supports linear and radial gradient elements.
Adds support for WOFF and WOFF2 fonts.
The new parameter selects alternate color palettes from COLR/CPAL color fonts, enabling different color schemes without embedding the font multiple times.
The new parameter restricts which Unicode characters a font covers.
The new parameter allows variable fonts to be used.
Bounding box support was added to the drawing API.
Color font glyphs can now be rendered in SBIX, CBDT/CBLC, SVG, COLRv0, and COLRv1 formats.
FlexTemplate elements now support dashed lines.
Gradient spread methods PAD, reflect, and repeat are supported.
The drawing API now supports gradients as fill or stroke colors.
Links can now target named destinations.
Native PDF/A compliance verification supports PDF/A-1B, 2B, 2U, 3B, 3U, 4, 4E, and 4F; accessible PDF/A documents are not yet supported.
The drawing API now supports Porter–Duff compositing operations.
Sweep (mesh) gradients are now supported.
Performance 1
Improves performance when rendering paths, SVGs, and opaque raster images with an alpha channel.
Behavior and default changes 14
Accepts CSS rgb(R, G, B) colors and surrounding spaces in color and bgcolor attributes.
Table, cell, hr and img dimensions accept CSS px and pt units and surrounding whitespace.
Ordered lists support <li value="N"> and continue subsequent numbering from that value.
Supports square bullets; Unicode fonts use ▪ and core fonts fall back to the bullet.
Encoding errors now identify the Unicode script and suggest a suitable font available on the system.
Markdown multi-cell text now supports unordered lists using *, - or + as bullet markers.
Homogeneous arrays use PDF serialization for strings and names, including encryption when applicable.
Python 3.15 is now officially supported.
Coordinates and corner radii now accept absolute length units.
opacity, fill-opacity and stroke-opacity accept percentages; out-of-range opacity is clamped to 0–1.
Fonts with both outline and bitmap glyphs now prefer outline glyphs.
Python 3.14 is now officially supported.
Basic support was added for the SVG currentColor value.
Support was added for more recent Python versions.
Fixes and other changes 88
Images are scaled down to 8 bits rather than converted to RGBA, and retain tRNS color-key transparency.
Values are serialized as PDF numbers without exponent notation.
Outlines count all visible descendants and link siblings by parent, retaining bookmarks when hierarchy starts below the top level.
Checksums for compressed embedded files are calculated from the original file bytes as required by the PDF specification.
font_style and emphasis setters are synchronized with font selection and state tracking.
The annotation rectangle's horizontal position is computed from path x coordinates so it encloses the drawn path.
Infinite numeric zoom values are rejected instead of producing invalid PDF numbers.
Repeated style letters are treated as the same style; style="BB" is bold.
An unknown borders_layout name raises ValueError instead of a bare AttributeError.
A cell with colspan below 1 spans one column instead of raising errors or breaking the column layout.
A text_align tuple with too few values now raises a clear ValueError naming the column instead of IndexError.
ncols below 1 raises a clear ValueError instead of a ZeroDivisionError or unrelated rendering error.
Tables replay with their rows and cells intact when an unbreakable block moves to a new page.
Unsupported align values on td, th and tr are ignored instead of raising ValueError.
Accepts legacy HTML colors written as six hex digits without a leading #.
Cells without explicit widths share remaining table space; colspan widths are divided equally among spanned columns.
Ignores transparent color and bgcolor values, preserving inherited text or background colors.
Invalid CSS color on a heading is ignored, preserving its color attribute or default color.
Invalid or sub-one colspan and rowspan values on table cells are treated as 1.
Uses the first available font in a <font face> list; generic serif, sans-serif and monospace families use core fonts.
Reads CSS font-size units on <font>; unitless numbers remain points.
An anchor without href, such as a named anchor, renders its text as plain text instead of raising KeyError.
Alphabetic ordered lists longer than 26 items continue with aa, ab, and start values below 1 display as numbers.
An unknown ordered-list type numbers items as 1, 2, 3 instead of raising NotImplementedError.
A rowspan extending past the final table row is stopped at that row.
Accepts ul type keywords in any case.
Empty or unknown ul type values keep the default bullet instead of raising NotImplementedError.
Oversized table widths render at page width with a warning; negative widths are ignored.
No longer warns about missing end tags for HTML void elements.
Aliases honor center and right alignment with core fonts when text shaping is enabled.
Years below 1000 are padded to four digits.
None values are serialized as PDF null instead of an invalid Python literal.
Numbers in arrays, dictionaries and destinations are written without exponent notation, preserving values and very small zoom factors.
CSS rgb() colors accept percentages in SVG import and FPDF.write_html, clamped to 0%–100%.
Byte strings and BytesIO inputs accept a UTF-8 BOM and XML whitespace after <svg> or <?xml> instead of going to the raster loader.
Color keywords are case-insensitive; fill and stroke accept transparent, which paints nothing like none.
Accepts percentages, clamps out-of-range values to 0–1, and combines with the color alpha channel.
Inline style declarations for stop-opacity take precedence over the corresponding presentation attribute.
Attributes accept scientific notation, such as width="1e2pt".
Malformed points draw up to the last complete point; empty points draw nothing.
Transform numbers may use scientific notation.
Bulleted paragraphs honor top margins, indented paragraphs retain the right boundary, and HTML list items honor TextStyle.t_margin.
PDF/A-1 documents using TrueType or CFF-based CID fonts now include a /CIDSet stream in each font descriptor, as required by ISO 19005-1.
Escaped Markdown markers adjacent to emphasis markers in link labels no longer lose literal characters or apply unintended styling.
List bullets now use correct font styling instead of inheriting styles from a preceding heading.
List line-height values that are not bare numbers are ignored, using the default line height instead of raising IndexError.
Now accepts 1-element sequences per CSS shorthand rules and preserves existing Padding instances without redundant allocations.
Fixes table cells landing in the wrong column when a row is covered by several rowspans that do not start in column order.
Percentage width and height values with surrounding whitespace no longer raise ValueError.
Fixes a visual gap in subsequent text rendering after a page alias when text shaping is enabled.
CMap mappings are split into blocks of at most 100 entries to meet the PDF specification.
Preserves boundary-neutral formatting during bidirectional text preprocessing.
Embeds CID-keyed CFF fonts as raw CFF programs so browser PDF viewers render them correctly.
Fixes the number of surviving escape characters.
Fixes text rendering when the first text on a page starts with a fallback glyph.
Dry runs now preserve link annotations and markdown formatting; ToC dry runs also preserve page order.
Can restore current_font when the selected font state has diverged.
Preserves consecutive markdown links without intervening spaces and supports markdown styling around links.
Treats RuntimeError like ImportError for the optional numpy import, so unsupported CPUs make numpy unavailable instead of causing import fpdf to fail.
Declares the default base state and display order so PDF viewers can list layers correctly.
Leading spaces on new lines inside preformatted blocks are no longer dropped.
Fixes rendering SVG arcs with very small sweeps that previously rounded to zero.
Counts SVG <switch> elements toward SVG complexity limits.
Font state no longer leaks onto the FPDF instance after text_columns() or text_region() exits, so subsequent cell() or write() calls use the caller's font.
Font state no longer leaks onto the FPDF instance after text_region() exits, so subsequent cell() or write() calls use the caller's font.
Avoids a spurious horizontal-space error when unbreakable text is split into many small fragments, such as by alternating fallback and main fonts.
Resets graphics state for ToC rendering and fixes page order after multi_cell dry runs in a ToC.
Fixes transform application on user space gradients.
Fixed the types for FPDF.add_font().
Fixed the types for FPDF.output().
Fixed the type for FPDF.title.
Reverted changes to ImageInfo that impacted the user-facing API.
Fixes an extra border rendered for empty tables using INTERNAL layout.
Fixes edge cases where tiny floating-point drift could trigger incorrect behavior.
Corrects the A5 page dimensions used when format is specified in the FPDF constructor.
ImageInfo now uses typed dictionaries for clearer usage and stronger typing.
Fixes parsing markdown sequences containing an escape character.
Adds remapping for Microsoft Symbol fonts with non-Unicode cmaps.
Escapes parentheses in more places, fixing embedding files whose filenames contain a single parenthesis; section names may also be affected.
Fixed a bug when merging fragments of different types.
GoTo actions for named destinations were fixed.
Destination page numbers are now updated when the ToC renderer spans multiple pages.
Detection logic changed to maintain compatibility with Pillow v12.
Fixed an issue with Markdown when fallback fonts contain non-alphanumeric characters.
Fixed rendering that caused visual distortions and incorrect filling.
Fixed missing cell clearance in spacing calculations.
The fvar font table is preserved to maintain compatibility with variable fonts.
Fixed a syntax error caused by an invalid
/Transparencydict when the PDF version is greater than 1.3.