pypi / pypdf
pypdf
What changed in pypdf 5 to 7, from its official release notes, upgrade guides and advisories. Sources checked 2026-11-26.
22 breaking79 security4 deprecations23 new APIs and options27 performance13 behavior and defaults2 tooling104 fixes and other
See which of these apply to your code, ranked, in your agent:
npx @unstale/cli initpypdf 734 changes
Breaking changes 6
add_outline_item is now keyword-only.
Support for cryptography versions below 43 has been removed.
File identifiers are now non-deterministic, changing how identifiers behave.
Image size limits are now applied more strictly.
Object streams with offsets that are not strictly increasing are now blocked.
Python 3.9 is no longer supported.
Security 5
Restricts work and memory used for cross-reference streams.
Limits inline image size on the known-size fallback path.
Limits overall page label size before using a fallback.
Image buffer sizes are determined using the actual bytes per pixel.
Work performed while decoding XFA forms is now limited.
Deprecations 1
Passing a boolean to remove_images is deprecated.
New APIs and options 1
Rectangle annotations can now be given a border color.
Performance 12
Reduces memory usage when removing whitespace during ASCIIHexDecode.
Indexes named destinations when appending a document.
Lists image identifiers only once when iterating over page images.
Decodes PDFDocEncoding strings using str.translate instead of per-character concatenation.
Per-character direction checks are skipped for left-to-right text.
Streams are no longer decoded to find identical objects.
The pure-Python RC4 implementation used without a crypto library is faster.
Content streams without text operators are no longer parsed, improving text extraction performance.
LZW decoding is faster for clear table markers.
The page label number tree is read once for all pages.
The PNG Up predictor is decoded a row at a time.
Right-to-left text runs are now built with a single join.
Behavior and default changes 1
A soft mask is scaled to the size of its image.
Fixes and other changes 8
Labels a page that lies between the /Limits of two page label kids.
Rejects slices with a zero step.
The operations in a replicated content stream are copied.
More rendering intents are handled for inline images.
Page reference lookup works for hierarchical page trees.
UTF-8 text strings are decoded.
Cloning now works for objects that require constructor arguments.
XMP packets are serialized without an XML declaration.
pypdf 6226 changes
Breaking changes 11
FlateDecode recovery is further restricted.
Text leading is no longer scaled by the font size.
Strict mode rejects typeless non-page /Kids entries.
Hex readers raise PdfStreamError when they encounter non-hexadecimal bytes.
Cross-reference streams with zero-only width values are disallowed.
Custom XML entity declarations are disallowed for XMP metadata.
Common page content modifications are blocked when a page is assigned to a reader.
The default limit for LZW decoding is reduced, changing the default amount of data decoded.
An explicit exception is raised when image mode is an empty array.
Limits the decompressed size for the FlateDecode filter to improve security.
Python 3.8 is no longer supported.
Security 74
Fixes loop detection when cloning DictionaryObject.
Limits the number of copied page attributes during flattening.
pypdf has possible large memory usage when parsing page tree
Detects EOF when reading a standard xref table trailer.
Limits the total number of cross-reference stream entries.
Uses the validated page count after decrypting a document.
Reads flat page label number trees once for all pages.
pypdf has possible large memory usage for exceptions in strict mode
pypdf has possible long runtimes/large memory usage for encrypted PDF files
pypdf: Possible long runtimes for repeated malformed cross-reference entries (Follow-up)
pypdf: Possible long runtimes for repeated references to the same missing object
Limits the size of the standard xref table.
Only /DCTDecode image data is opened with the Pillow JPEG plugin.
Improves performance and limits field work.
pypdf: Possible large memory usage when parsing arrays and dictionaries
Limits stream parsing work.
Prevents cyclic tree handling.
pypdf: Possible infinite loop in PdfWriter.find_outline_item
Restricts values to the allowed range in CCITTFaxDecode.
pypdf: Possible infinite loop when hitting EOF in standard xref table
Limits work per stream, including filter count and accumulated decoding work, to improve security.
Limits the size of alphabetical page labels.
pypdf: Possible long runtimes when generating appearance streams
pypdf: Possible long runtimes with large amount of embedded files
The allowed length of tokens parsed by parse_bfchar is limited.
pypdf: Possible large memory usage for large /ToUnicode streams (Follow-up 2)
pypdf: Possible large memory usage when parsing font data
Entry counts are limited for TrueType and Type1 font /Widths.
The allowed length of indirect object tokens is limited.
Limits values for Roman numerals.
Limits iterations during outline retrieval to improve security.
Limits iterations during XForm text extraction to improve security.
pypdf: Possible infinite loop for TreeObject.insert_child
pypdf: Possible large memory usage for large /ToUnicode streams
pypdf: Possible long runtimes/large memory usage for large CID font width ranges
Improves read_until_whitespace performance.
Limits token length for ToUnicode entries.
pypdf: Possible infinite loop for not terminated inline images (ASCII85 and ASCIIHex filter)
pypdf: Possible infinite loop for not terminated inline images
Recovery when reading a broken cross-reference table is faster.
A general limit is applied to requested image size.
pypdf: Missing stream length values ignore defined limits
Detects multi-hop cyclic /Pages trees during flattening to prevent SIGSEGV when processing malformed PDFs.
pypdf: Possible infinite loop when processing threads/articles in writer
Avoids infinite loops during outline processing and text extraction.
pypdf: Possible infinite loop when retrieving fonts for layout-mode text extraction
pypdf: Inefficient decoding of FlateDecode PNG predictor streams
pypdf: Possible large memory usage for form XObjects during text extraction
Improved loop control during text extraction.
Limits input size and element count for XMP metadata.
pypdf: Possible large memory usage for large offsets for layout mode text
Limits are introduced for FlateDecode parameters.
Limits are introduced for image decoding.
pypdf: Manipulated FlateDecode image dimensions can exhaust RAM
pypdf: Possible long runtimes for wrong size values in incremental mode
Limits the allowed size of xref and object streams.
AES padding is correctly verified during decryption.
Avoids an infinite loop when reading broken files.
Performance is improved and the length of array-based content streams is limited.
pypdf: manipulated stream length values can exhaust RAM
The ASCIIHexDecode filter is faster, which may improve performance when decoding ASCIIHex data.
Output length for the RunLengthDecode filter can now be limited.
A decompression limit is used when retrieving XFA data, improving security when processing PDFs with XFA data.
pypdf has a possible infinite loop when loading circular /Prev entries in cross-reference streams
The number of FlateDecode recovery attempts is limited.
The size of /ToUnicode entries is limited.
Cyclic references are detected when accessing children, preventing unsafe traversal.
Cyclic references are detected when retrieving outlines.
Handling of partially broken PDF files was improved, which may affect how such files are processed.
pypdf has possible long runtimes for malformed startxref
pypdf has possible long runtimes for missing /Root object with large /Size values
Limits jbig2dec memory usage.
LZWDecode streams can now have their size limited.
pypdf possibly loops infinitely when reading DCT inline images without EOF marker
Deprecations 3
The PdfWriter method add_js is being replaced.
The previously missed inline_images setter is deprecated.
Support for abbreviations in decode_stream_data is deprecated.
New APIs and options 19
Allows custom fit modes for named destinations.
Adds support for the BrotliDecode filter in PDF 2.0.
Use apply_configuration as a context manager to temporarily overwrite configuration values.
Set disable_legacy_handling to avoid legacy handling overhead after migrating configuration overwrites.
Use overwrite_configuration to change configuration values for the whole session.
Adds an actions base class.
Allows keeping the original PDF header in non-incremental clone mode.
Adds support for RTL appearance streams with Arabic characters.
Adds a way to check whether an image is displayed on a given page.
Adds Japanese predefined CMaps.
A Font can now be initialised from an embedded font file.
Exposes the /Perms verification result on the Encryption object.
Adds /IRT (in-reply-to) support for markup annotations.
Font resources can now be added for 14 Adobe Core fonts in text widget annotations.
FontDescriptor can be initiated from an embedded font resource.
Comb fields in text widget annotations can now be parsed and formatted.
Text can be wrapped and aligned in flattened PDF forms.
Adds a strict parameter to PDFWriter.
BlackIs1 functionality is moved to tiff_header.
Performance 14
Avoids scanning all objects in get_outline_root.
Collects named destinations once when resolving links.
Avoids repeated full file loads.
Speeds up cloning direct objects.
Parses an embedded CFF font program once per stream, reducing repeated parsing work.
Speeds up parsing numbers, indirect references, names and nulls.
Reduces the number of full data lookups for the attachment mapping API.
Repeated character lookups are cached during text extraction.
Builds /ToUnicode source-code bytes directly, improving the parsing path.
Avoids a per-pixel getpixel loop for 1-bit indexed images.
Retrieval of named destinations in the reader is optimized.
Fixes O(n²) performance in NameObject read/write.
All objects in an ObjStm are batch-parsed on first access.
The loop for layout mode text extraction was optimized, improving its performance.
Behavior and default changes 11
Declares official support for Python 3.15.
Encoding is also parsed for embedded CFF Type1 fonts.
Allows arbitrary rotations and applies rotations for annotation appearance streams.
Considers more encodings for Type1 core fonts.
Adds an ActualText tag when producing an RTL appearance stream.
Collects all character widths, including widths for characters that cannot be Unicode mapped.
SASLprep (RFC 4013) is implemented for AES-256 password normalization.
A CID font resource from a font file can encode more characters.
MD5 key derivation is skipped for AES-256 encrypted PDFs.
Generated text appearance streams have embellishments, affecting the appearance of generated text.
Early EOD for RunLengthDecode now produces a warning instead of an error.
Tooling 2
Declares protocol data members on PdfReader and PdfWriter.
The type hint uses Mapping instead of dict.
Fixes and other changes 92
Reverts rejection of unsupported key lengths in the /Encrypt dictionary.
Avoids excessive error messages.
Resolves indirect widths in CID font /W arrays.
Keeps 8-bit DeviceRGB image mode.
Preserves all annotation quadrilaterals when merging pages.
Decodes UniGB-UTF16 CMaps as UTF-16BE.
Avoids overwriting unread objects in add_form_topname.
Treats NUL as whitespace in ArrayObject.
Reads an indirect page box on a writer page.
Only reads the color operator from a text field's default appearance.
Accepts an %%EOF marker that is not at the start of a line.
Adds more robust guards around fontTools.
Drops a /Kids entry resolving to null instead of raising a cycle error.
Reports the correct page number for identical pages.
Flattens the page tree iteratively.
Ignores invalid character codes for TrueType and Type1 font widths.
Decrypts the XMP metadata stream unless /EncryptMetadata is false.
A string rect passed to add_uri is parsed into a rectangle.
Appending pages with non-terminal fields no longer copies unrelated pages.
Existing internal link targets use a page reference.
Arabic-Indic digits are no longer reversed during text extraction.
Compatibility is fixed for fonttools versions below 4.58.0.
FreeText default appearance uses the font color.
The letters for /S /A and /S /a page labels repeat past Z.
visitor_text uses the current text matrix.
Draw borders and backgrounds for appearance streams and annotations.
Annotations without a subtype are handled during merge.
Duplicate dictionary keys are detected even when the first value is falsy.
An empty /Filter array is treated as no filter when extracting images.
Setting is_open=False collapses outline items.
A non-array destination no longer causes a crash.
Trailing duplicate %%EOF markers are skipped when locating startxref.
The annotation appearance stream matrix is updated when a page is transformed.
Text extraction in layout mode is more lenient about space width.
Repeated page references are now allowed.
The RC4 fallback is improved when cryptography cannot provide it.
remove_from_tree() now works on outline items.
Escapes parentheses only for 8-bit fonts.
Keeps Adobe CMYK inversion when an explicit /Decode is present.
Fixes false inline image end markers.
Preserves internal Link annotations when appending or merging PDFs.
Applies character spacing per glyph during layout-mode extraction.
Recovers the trailer from a cross-reference stream when rebuilding the xref.
Decodes low-bit DeviceRGB images as RGB instead of palette.
Correctly handles IndirectObject in DecodeParms.
Expands low-bit samples for images without a filter.
Fixes an UnboundLocalError when reading a malformed cross-reference table entry.
Accepts an inline image EI marker at the end of a content stream.
Handles a /Pages node without /Kids during flattening.
Recovers from a corrupt trailing startxref pointer.
Prevents cyclic parent hierarchies for inherited dictionaries.
Deals with an invalid first code in the LZW decoder.
AppearanceStream honors a user-set font name when annotations are not flattened.
Excessive whitespace in layout mode text extraction is avoided.
Fixes a KeyError when inserting fresh children.
AES padding length can now be fixed in non-strict mode.
Decryption errors now take the strict mode setting into account.
The remove_orphans option is used when compressing identical objects.
Fixes link pairing when annotations include non-links.
Fixes stale cached objects originating from non-authoritative object streams.
Fixes PdfReadError when an xref table contains comments before the trailer.
Resolves an UnboundLocalError for xobjs.
Avoids sharing array-based content streams between pages.
Avoids accessing an invalid page when inserting a blank page under some conditions.
Invalid annotations are now handled in extract_links.
Fixes a wrong LUT size error.
Fixes handling of page boxes defined on /Pages.
Avoids division by zero when decoding FlateDecode PNG prediction.
Avoids applying its own object replacement logic when replacing page contents.
Fixes an UnboundLocalError when updating page form field values containing /Sig.
Fixes AESV2 decryption when the encrypt dictionary is missing /Length.
Fixes merging when annotations point to NullObject.
Checks whether self._info is None in compress_identical_objects.
Avoids invalid loads for ICCBased FlateDecode images in mode 1.
Handles /AcroForm being a NullObject.
Handles missing font bounding boxes gracefully.
Multi-byte BOM-like sequences are no longer treated as BOMs.
Empty FlateDecode outputs are avoided without warning.
Compatibility with Pillow 12.1.0 and later was fixed.
Allows fallback to PBM files when jbig2dec lacks PNG support.
Allows deleting annotations that do not exist.
Fixes a KeyError when flattening a form field whose resources lack /Font.
Choice fields without an /Opt key no longer cause a failure.
Whitespace is silently ignored when detecting an Adobe Ascii85 suffix.
JPEG image quality is preserved by default.
Fixes missing PreventGC when cloning.
Fixes PdfWriter.append failing when there are articles being None.
PageObject.scale() no longer scales the media box incorrectly.
Handling of malformed cross-reference tables is improved.
pypdf now deals with incorrect sizes in incremental PDF files.
Handling of zero-length StreamObject instances is fixed.
Go-To actions without a destination are skipped.
pypdf 514 changes
Breaking changes 5
AnnotationBuilder is removed; use annotations instead.
PdfMerger is removed; use PdfWriter instead.
Reports PdfReadError instead of RecursionError.
Support for Python 3.7 is dropped.
Raises PdfReadError when /Root is missing from the trailer.
New APIs and options 3
Adds the capability to remove /Info from a PDF.
PdfWriter gains incremental capability.
Adds UniGB-UTF16 encodings.
Performance 1
PDF files are compressed by merging identical objects.
Behavior and default changes 1
Metadata accepts UTF strings.
Fixes and other changes 4
Fixes extract_text() issues on damaged PDFs.
Handles images with empty data when processing an image from bytes.
Robustifies set_data().
Fixes sheared images.