Releases: py-pdf/fpdf2
New vector drawing API & SVG embedding
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
HACKTOBERFEST! Detect oversized images, new methods to draw arcs & regular polygons, improved documentation
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:
-
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 settingpdf.allow_images_transparency = False
in order to allow compliance with PDF/A-1 -
FPDF.arc
: new method added to draw arcs in a PDF document. -
FPDF.solid_arc
: new method added 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 astyle
parameter in common.
They now all properly accept a value of"D"
and raise aValueError
for invalid values.
Deprecated
dashed_line()
is now deprecated in favor ofset_dash_pattern()
Ensuring support for old field names in `Template.code39` for backward compatibility
FlexTemplate, markdown in multi_cell & bug fixes
Added
Template()
has gained a more flexible cousinFlexTemplate()
, 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 optionalheading_sizes
parameter- a subclass of
HTML2FPDF
can now easily be used by settingFPDF.HTML2FPDF_CLASS
,
cf. documentation
Fixed
Template
:split_multicell()
will not write spurious font data to the target document anymore, thanks to @gmischlerTemplate
: rotation now should work correctly in all situations, thanks to @gmischlerwrite_html
: headings (<h1>
,<h2>
...) can now contain non-ASCII characters without triggering aUnicodeEncodeError
Template
: CSV column types are now safely parsed, thanks to @gmischlercell(..., 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 arotation
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 fromx/y/w/h
tox1/y1/y2/size
Support for emojis & justified text in templates
Added
- support for emojis! Me precisely unicode characters above
0xFFFF
in general, thanks to @moe-25 Template
can now insert justified textget_scale_factor
utility function to obtainFPDF.k
without having to create a documentconvert_unit
utility function to convert a number,x,y
point, or list ofx,y
points from one unit to another unit
Changed
fpdf.FPDF()
constructor now accepts ints or floats as a unit, and raises aValueError
if an invalid unit is provided.
Fixed
Template
background
property is now properly supported - #203
⚠️ Beware that its default value changed from0
to0xffffff
, 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 theFPDF.code39
method when those characters are missing.
Fixed
- Detect missing
uni=True
when loading cached fonts (page numbering was missing digits)
FPDF.circle, support for named HTML colors & repeating table headers on each page
Added
- disable font caching when
fpdf.FPDF
constructor invoked withfont_cache_dir=None
, thanks to @moe-25 ! FPDF.circle
: new method added, thanks to @viraj-shah18 !HTMLMixin
/HTML2FPDF
: support setting HTML font colors by name and short hex codesFPDF.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 optionalx
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)
Bugfixes related to page breaks & unicode fonts
Fixed
- erroneous page breaks occured for full-width / full-height images
- rendering issue of non-ASCII characaters with unicode fonts
JPEG storage improvements, basic Markdown styling & presentation transitions
Changed
- now
fpdf2
uses the newly supportedDCTDecode
image filter for JPEG images,
instead ofFlateDecode
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
: thew
(width) parameter becomes optional, with a default value ofNone
, meaning to generate a cell with the size of the text content provided- the
h
(height) parameter of thecell
,multi_cell
&write
methods gets a default value change,None
, meaning to use the current font size - removed the useless
w
&h
parameters of theFPDF.text_annotation()
method
Added
- new
FPDF.add_action()
method, documented in the Annotations section FPDF.cell
: new optionalmarkdown=True
parameter that enables basic Markdown-like styling:**bold**, __italics__, --underlined--
FPDF.cell
: new optional booleancenter
parameter that positions the cell horizontallyFPDF.set_link
: new optionalzoom
parameter that sets the zoom level after following the link.
Currently ignored by Sumatra PDF Reader, but observed by Adobe Acrobat reader.HTMLMixin
/HTML2FPDF
: now supportalign="justify"
- new method
FPDF.image_filter
to control the image filters used for images FPDF.add_page
: new optionalduration
&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
, usingtype="C39"
Fixed
- avoid an
Undefined font
error when usingwrite_html
with unicode bold or italics fonts
Deprecated
- the
FPDF.set_doc_option()
method is deprecated in favour of just setting thecore_fonts_encoding
property
on an instance ofFPDF
- the
fpdf.SYSTEM_TTFONTS
configurable module constant is now ignored
Minor bug fix
Fixed
- a bug in the
deprecation
module that prevented to configurefpdf2
constants at the module level
Minor bug fix
Fixed
- a "fake duplicates" bug when a
Pillow.Image.Image
was passed toFPDF.image