def to_pymupdf_doc(self):
        """
        Transforms the PDF into a PyMuPDF (fitz) document.
        If modifications have been made using PdfWriter, it saves to a temporary file first.
        This function dynamically imports PyMuPDF (fitz), requiring it only if this method is called.
        """
        try:
            import fitz  # type: ignore
        except ImportError as err:
            raise ImportError(
                "PyMuPDF (fitz) is not installed. This method requires PyMuPDF."
            ) from err

        if not self.writer.pages:
            return fitz.open(self.file_path)

        byte_stream = io.BytesIO()
        self.writer.write(byte_stream)
        return fitz.open(None, byte_stream)

        Transforms the PDF into a PyMuPDF (fitz) document.
        If modifications have been made using PdfWriter, it saves to a temporary file first.
        This function dynamically imports PyMuPDF (fitz), requiring it only if this method is called.
        
src/openparse/pdf.py