Configuration
- class pypdf.Configuration(maximum_declared_stream_length: int = 75000000, array_based_stream_maximum_output_length: int = 75000000, jbig2_maximum_output_length: int = 75000000, lzw_maximum_output_length: int = 75000000, run_length_maximum_output_length: int = 75000000, zlib_maximum_output_length: int = 75000000, zlib_maximum_recovery_input_length: int = 5000000, flate_maximum_columns: int = 250000, flate_maximum_row_length: int = 4000000, image_maximum_buffer_size: int = 75000000, xmp_maximum_input_length: int = 5000000, xmp_maximum_element_count: int = 100000, outline_maximum_entries: int = 100000, outline_maximum_depth: int = 100, page_tree_maximum_entries: int = 100000, page_tree_maximum_depth: int = 100, xform_maximum_invocations_per_extraction: int = 5000, jbig2dec_binary: str | None = <factory>, page_merge_box: ~typing.Literal['cropbox', 'trimbox'] = 'cropbox', disable_legacy_handling: bool = False)[source]
Bases:
objectConfiguration used while processing PDF files.
These limits mostly protect against excessive resource consumption caused by malformed or malicious PDF files.
Note
Avoid relying on specific implementation details of this class. The main public API consists of the values being considered read-only for each instance with the overwrite method to create a new instance with the specified values changed.
- maximum_declared_stream_length: int = 75000000
The maximum allowed declared
/Lengthvalue for streams.
- array_based_stream_maximum_output_length: int = 75000000
The maximum allowed output length for array-based streams.
- jbig2_maximum_output_length: int = 75000000
The maximum allowed number of uncompressed bytes during decompression when using the
/JBIG2Decodefilter (JBIG2 images).
- lzw_maximum_output_length: int = 75000000
The maximum allowed number of uncompressed bytes during decompression when using the
/LZWDecodefilter (LZW compression).
- run_length_maximum_output_length: int = 75000000
The maximum allowed number of uncompressed bytes during decompression when using the
/RunLengthDecodefilter (run-length compression).
- zlib_maximum_output_length: int = 75000000
The maximum allowed number of uncompressed bytes during decompression when using the
/FlateDecodefilter (zlib compression).
- zlib_maximum_recovery_input_length: int = 5000000
The maximum allowed number of bytes to attempt the recovery with when using the
/FlateDecodefilter (zlib compression).
- flate_maximum_columns: int = 250000
The maximum allowed number of columns when using the
/FlateDecodefilter.
- flate_maximum_row_length: int = 4000000
The maximum allowed row length when using the
/FlateDecodefilter.
- image_maximum_buffer_size: int = 75000000
The maximum allowed number of bytes to allocate for images.
- xmp_maximum_input_length: int = 5000000
The maximum allowed actual decompressed stream length in bytes for XMP data.
- xform_maximum_invocations_per_extraction: int = 5000
The maximum allowed number of
/XObjectforms per page during text extraction.
- jbig2dec_binary: str | None
The location of the
jbig2decbinary.This either is a string holding the path to the binary, or
Noneif the binary could not be found or the binary should not be called.
- disable_legacy_handling: bool = False
Temporary configuration value for applications which do not rely on old overwrites and thus are able to skip legacy handling.
This disables looking for changes of the old constants during each initialization of the reader class. Please note that while this reduces the required overhead, it will disable all related deprecation warnings/errors. Setting this flag while legacy constants are intentionally being modified is unsupported/incorrect.
After the deprecation period, this configuration value will be removed with its own deprecation period as well.
- with_overwrites(**kwargs: Any) Configuration[source]
Creates a new configuration with the specified values overwritten.
- Parameters:
**kwargs – Configuration field names and their new values.
- Returns:
A new configuration with the specified values overwritten.
- pypdf.apply_configuration(configuration: Configuration | None = None, **overwrites: Any) Iterator[Configuration][source]
Temporarily overwrite the configuration.
- Parameters:
configuration – A direct configuration instance to use.
**overwrites – Configuration parameters to overwrite in the current or given configuration.
- Returns:
The new configuration.
- pypdf.get_configuration() Configuration[source]
Get the current configuration.
- Returns:
The current configuration.
- pypdf.overwrite_configuration(configuration: Configuration | None = None, **overwrites: Any) Configuration[source]
Overwrite the configuration for the current execution context.
- Parameters:
configuration – A direct configuration instance to use.
**overwrites – Configuration parameters to overwrite in the current or given configuration.
- Returns:
The new configuration.