3.0.0
Changes (Release 3.0.0)
Summary (pypdfium2)
-
Support model
API-breaking changes
- If the target page of a bookmark cannot be identified,
OutlineItem.page_index
is nowNone
rather than-1
, to avoid accidental reverse list indexing and to enforce that callers properly handle this case. Moreover,OutlineItem.is_closed
is nowNone
rather thanFalse
if the bookmark has no kids. PdfPageObject.get_type()
was replaced with atype
attribute.PdfPage.count_objects()
was removed. UsePdfPage.get_objects()
or the raw PDFium API instead.- If a negative index is passed to
PdfDocument.new_page()
, it is now interpreted in reversed direction, rather than inserting at the beginning. - PDFium is now provided with an external, python-allocated buffer for rendering. This has numerous advantages, most notably that callers don't need to free resources anymore.
PdfPage.render_base()
now directly returns a ctypes ubyte array;BitmapDataHolder
has been removed. - Changed rendering parameters
annotations
was renamed todraw_annots
colour
was renamed tofill_colour
and now only takes a list of 4 values for simplicity - it may not be 3 values orNone
anymoreno_antialias
has been replaced with separate boolean optionsno_smoothtext
,no_smoothimage
, andno_smoothpath
Other changes
OutlineItem
now contains information on the number of sub-items (n_kids
attribute).- All document-level methods that take a page index now accept negative values for reverse indexing (except the rendering methods).
- New method
PdfDocument.get_page_size()
to retrieve page size by index without needing to load aPdfPage
(usesFPDF_GetPageSizeByIndexF()
under the hood). - New rendering parameters added:
colour_scheme
,fill_to_stroke
,force_halftone
,draw_forms
,rev_byteorder
,prefer_bgrx
,force_bitmap_format
,extra_flags
,allocator
, andmemory_limit
. - Added new
render_to()
functions toPdfPage
andPdfDocument
that take a custom bitmap converter, to transform the ctypes array to a different object. A set of built-in converters is provided with theBitmapConv
class. Confer the updated API documentation for details. The previous rendering functions (render_topil()
render_tobytes()
, ...) are still around as aliases but might be deprecated eventually. - New rendering target
numpy_ndarray
added. - The
pil_image
rendering target now accepts aprefer_la
parameter to request automatic conversion ofBGRA
/RGBA
toLA
if rendering in greyscale mode with alpha channel. PdfPage.get_objects()
can now recursively descend into Form XObjects.- Form environments are now initialised/exited on document level rather than on page rendering. In the course of this work, a segmentation fault source was eliminated, related to a formerly undocumented requirement of PDFium regarding object lifetime. Whether the segmentation fault would actually take place was dependent on Python garbage collection behaviour. This did not appear to happen under normal circumstances, so the issue remained unnoticed for a long time.
- If the target page of a bookmark cannot be identified,
-
Setup code
$PYP_TARGET_PLATFORM
was renamed to$PDFIUM_BINARY
, the valuesdist
was renamed tonone
.- When doing an automatic release, repository changes are now only pushed after successful wheel building, to avoid leaving the repository in an invalid state in case some earlier step fails.
- pypdfium2 now declares a no-op setuptools extension to prevent wheel content from landing in a
purelib
folder. Some systems use this information to separate platform-dependent packages from pure-python packages (i. e./usr/lib64
instead of/usr/lib
). Confer PEP 427. - Autorelease now properly takes existing beta tags into account for its version changes.
- PDFium's commit log is now shown with GitHub releases.
- The wheel packaging script now restores in-tree artefacts from a possible editable install.
- Platform files are now detected in a more robust way. If missing, a proper exception will be raised.
- Platform data directories are now annotated with a text file storing the pdfium version, to prevent a possible mismatch between the state of
version.py
and the actual version of the used binary. The update and build scripts do not directly change the main version file anymore, but defer the changes tosetup.py
. - Missing platform files are now always procured implicitly on installation. If platform files exist already but are outdated, they will be updated by default. You may opt out by creating an empty file called
.lock_autoupdate.txt
indata/
. - A
MANIFEST.in
file was added to avoid being dependent onsetuptools_scm
. - On setup, dependency checks are now only done for system commands. The wonky implicit installation of missing Python packages was removed. If opting out of build isolation, callers should properly install setup dependencies beforehand.
-
Documentation
- Rewrote the project's
README.md
. Added more support model examples and an extensive guide regarding the raw PDFium/ctypes API. - Improved docstrings and included type hints.
- Rewrote the project's