diff --git a/pypdf/_writer.py b/pypdf/_writer.py index c4fc07c7f..463bc2988 100644 --- a/pypdf/_writer.py +++ b/pypdf/_writer.py @@ -392,37 +392,6 @@ def __exit__( if self.fileobj and not self._cloned: self.write(self.fileobj) - def _repr_mimebundle_( - self, - include: Union[None, Iterable[str]] = None, - exclude: Union[None, Iterable[str]] = None, - ) -> Dict[str, Any]: - """ - Integration into Jupyter Notebooks. - - This method returns a dictionary that maps a mime-type to its - representation. - - .. seealso:: - - https://ipython.readthedocs.io/en/stable/config/integrating.html - """ - pdf_data = BytesIO() - self.write(pdf_data) - data = { - "application/pdf": pdf_data, - } - - if include is not None: - # Filter representations based on include list - data = {k: v for k, v in data.items() if k in include} - - if exclude is not None: - # Remove representations based on exclude list - data = {k: v for k, v in data.items() if k not in exclude} - - return data - @property def pdf_header(self) -> str: """ @@ -3299,6 +3268,37 @@ def _set_page_label( page_labels[NameObject("/Nums")] = nums self._root_object[NameObject(CatalogDictionary.PAGE_LABELS)] = page_labels + def _repr_mimebundle_( + self, + include: Union[None, Iterable[str]] = None, + exclude: Union[None, Iterable[str]] = None, + ) -> Dict[str, Any]: + """ + Integration into Jupyter Notebooks. + + This method returns a dictionary that maps a mime-type to its + representation. + + .. seealso:: + + https://ipython.readthedocs.io/en/stable/config/integrating.html + """ + pdf_data = BytesIO() + self.write(pdf_data) + data = { + "application/pdf": pdf_data, + } + + if include is not None: + # Filter representations based on include list + data = {k: v for k, v in data.items() if k in include} + + if exclude is not None: + # Remove representations based on exclude list + data = {k: v for k, v in data.items() if k not in exclude} + + return data + def _pdf_objectify(obj: Union[Dict[str, Any], str, float, List[Any]]) -> PdfObject: if isinstance(obj, PdfObject):