We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
[documents] Add basic document reader
For documents to be analyzed, we first need to add a utility for document reading (PDF mostly). The following specs would be nice to have:
- inherit for a shared reader class ("DocumentReader" for instance)
- to be located in the `doctr.documents.reader`  module

The following formats should be handled:
- [x] PDF (#8, #25): this resource would be nice to check: https://github.com/pymupdf/PyMuPDF
- [x] PNG (#30)
- [x] JPG (#30)


cc @charlesmindee 

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `doctr/documents/reader.py`
Content:
```
1 # Copyright (C) 2021, Mindee.
2 
3 # This program is licensed under the Apache License version 2.
4 # See LICENSE or go to <https://www.apache.org/licenses/LICENSE-2.0.txt> for full license details.
5 
6 import fitz
7 import numpy as np
8 import cv2
9 from typing import List, Tuple, Optional, Any
10 
11 __all__ = ['read_pdf']
12 
13 
14 def read_pdf(file_path: str, **kwargs: Any) -> List[np.ndarray]:
15     """Read a PDF file and convert it into an image in numpy format
16 
17     Example::
18         >>> from doctr.documents import read_pdf
19         >>> doc = read_pdf("path/to/your/doc.pdf")
20 
21     Args:
22         file_path: the path to the PDF file
23     Returns:
24         the list of pages decoded as numpy ndarray of shape H x W x 3
25     """
26 
27     # Read pages with fitz and convert them to numpy ndarrays
28     return [convert_page_to_numpy(page, **kwargs) for page in fitz.open(file_path)]
29 
30 
31 def convert_page_to_numpy(
32     page: fitz.fitz.Page,
33     output_size: Optional[Tuple[int, int]] = None,
34     rgb_output: bool = True,
35 ) -> np.ndarray:
36     """Convert a fitz page to a numpy-formatted image
37 
38     Args:
39         page: the page of a file read with PyMuPDF
40         output_size: the expected output size of each page in format H x W
41         rgb_output: whether the output ndarray channel order should be RGB instead of BGR.
42 
43     Returns:
44         the rendered image in numpy format
45     """
46 
47     transform_matrix = None
48 
49     # If no output size is specified, keep the origin one
50     if output_size is not None:
51         scales = (output_size[1] / page.MediaBox[2], output_size[0] / page.MediaBox[3])
52         transform_matrix = fitz.Matrix(*scales)
53 
54     # Generate the pixel map using the transformation matrix
55     stream = page.getPixmap(matrix=transform_matrix).getImageData()
56     # Decode it into a numpy
57     img = cv2.imdecode(np.frombuffer(stream, dtype=np.uint8), cv2.IMREAD_UNCHANGED)
58 
59     # Switch the channel order
60     if rgb_output:
61         img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
62 
63     return img
64
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/doctr/documents/reader.py b/doctr/documents/reader.py
--- a/doctr/documents/reader.py
+++ b/doctr/documents/reader.py
@@ -8,7 +8,36 @@
 import cv2
 from typing import List, Tuple, Optional, Any
 
-__all__ = ['read_pdf']
+__all__ = ['read_pdf', 'read_img']
+
+
+def read_img(
+    file_path: str,
+    output_size: Optional[Tuple[int, int]] = None,
+    rgb_output: bool = True,
+) -> np.ndarray:
+    """Read an image file into numpy format
+
+    Example::
+        >>> from doctr.documents import read_img
+        >>> page = read_img("path/to/your/doc.jpg")
+
+    Args:
+        file_path: the path to the image file
+        output_size: the expected output size of each page in format H x W
+        rgb_output: whether the output ndarray channel order should be RGB instead of BGR.
+    Returns:
+        the page decoded as numpy ndarray of shape H x W x 3
+    """
+
+    img = cv2.imread(file_path, cv2.IMREAD_COLOR)
+    # Resizing
+    if isinstance(output_size, tuple):
+        img = cv2.resize(img, output_size[::-1], interpolation=cv2.INTER_LINEAR)
+    # Switch the channel order
+    if rgb_output:
+        img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
+    return img
 
 
 def read_pdf(file_path: str, **kwargs: Any) -> List[np.ndarray]:

{"golden_diff": "diff --git a/doctr/documents/reader.py b/doctr/documents/reader.py\n--- a/doctr/documents/reader.py\n+++ b/doctr/documents/reader.py\n@@ -8,7 +8,36 @@\n import cv2\n from typing import List, Tuple, Optional, Any\n \n-__all__ = ['read_pdf']\n+__all__ = ['read_pdf', 'read_img']\n+\n+\n+def read_img(\n+    file_path: str,\n+    output_size: Optional[Tuple[int, int]] = None,\n+    rgb_output: bool = True,\n+) -> np.ndarray:\n+    \"\"\"Read an image file into numpy format\n+\n+    Example::\n+        >>> from doctr.documents import read_img\n+        >>> page = read_img(\"path/to/your/doc.jpg\")\n+\n+    Args:\n+        file_path: the path to the image file\n+        output_size: the expected output size of each page in format H x W\n+        rgb_output: whether the output ndarray channel order should be RGB instead of BGR.\n+    Returns:\n+        the page decoded as numpy ndarray of shape H x W x 3\n+    \"\"\"\n+\n+    img = cv2.imread(file_path, cv2.IMREAD_COLOR)\n+    # Resizing\n+    if isinstance(output_size, tuple):\n+        img = cv2.resize(img, output_size[::-1], interpolation=cv2.INTER_LINEAR)\n+    # Switch the channel order\n+    if rgb_output:\n+        img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)\n+    return img\n \n \n def read_pdf(file_path: str, **kwargs: Any) -> List[np.ndarray]:\n", "issue": "[documents] Add basic document reader\nFor documents to be analyzed, we first need to add a utility for document reading (PDF mostly). The following specs would be nice to have:\r\n- inherit for a shared reader class (\"DocumentReader\" for instance)\r\n- to be located in the `doctr.documents.reader`  module\r\n\r\nThe following formats should be handled:\r\n- [x] PDF (#8, #25): this resource would be nice to check: https://github.com/pymupdf/PyMuPDF\r\n- [x] PNG (#30)\r\n- [x] JPG (#30)\r\n\r\n\r\ncc @charlesmindee \n", "before_files": [{"content": "# Copyright (C) 2021, Mindee.\n\n# This program is licensed under the Apache License version 2.\n# See LICENSE or go to <https://www.apache.org/licenses/LICENSE-2.0.txt> for full license details.\n\nimport fitz\nimport numpy as np\nimport cv2\nfrom typing import List, Tuple, Optional, Any\n\n__all__ = ['read_pdf']\n\n\ndef read_pdf(file_path: str, **kwargs: Any) -> List[np.ndarray]:\n    \"\"\"Read a PDF file and convert it into an image in numpy format\n\n    Example::\n        >>> from doctr.documents import read_pdf\n        >>> doc = read_pdf(\"path/to/your/doc.pdf\")\n\n    Args:\n        file_path: the path to the PDF file\n    Returns:\n        the list of pages decoded as numpy ndarray of shape H x W x 3\n    \"\"\"\n\n    # Read pages with fitz and convert them to numpy ndarrays\n    return [convert_page_to_numpy(page, **kwargs) for page in fitz.open(file_path)]\n\n\ndef convert_page_to_numpy(\n    page: fitz.fitz.Page,\n    output_size: Optional[Tuple[int, int]] = None,\n    rgb_output: bool = True,\n) -> np.ndarray:\n    \"\"\"Convert a fitz page to a numpy-formatted image\n\n    Args:\n        page: the page of a file read with PyMuPDF\n        output_size: the expected output size of each page in format H x W\n        rgb_output: whether the output ndarray channel order should be RGB instead of BGR.\n\n    Returns:\n        the rendered image in numpy format\n    \"\"\"\n\n    transform_matrix = None\n\n    # If no output size is specified, keep the origin one\n    if output_size is not None:\n        scales = (output_size[1] / page.MediaBox[2], output_size[0] / page.MediaBox[3])\n        transform_matrix = fitz.Matrix(*scales)\n\n    # Generate the pixel map using the transformation matrix\n    stream = page.getPixmap(matrix=transform_matrix).getImageData()\n    # Decode it into a numpy\n    img = cv2.imdecode(np.frombuffer(stream, dtype=np.uint8), cv2.IMREAD_UNCHANGED)\n\n    # Switch the channel order\n    if rgb_output:\n        img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)\n\n    return img\n", "path": "doctr/documents/reader.py"}], "after_files": [{"content": "# Copyright (C) 2021, Mindee.\n\n# This program is licensed under the Apache License version 2.\n# See LICENSE or go to <https://www.apache.org/licenses/LICENSE-2.0.txt> for full license details.\n\nimport fitz\nimport numpy as np\nimport cv2\nfrom typing import List, Tuple, Optional, Any\n\n__all__ = ['read_pdf', 'read_img']\n\n\ndef read_img(\n    file_path: str,\n    output_size: Optional[Tuple[int, int]] = None,\n    rgb_output: bool = True,\n) -> np.ndarray:\n    \"\"\"Read an image file into numpy format\n\n    Example::\n        >>> from doctr.documents import read_img\n        >>> page = read_img(\"path/to/your/doc.jpg\")\n\n    Args:\n        file_path: the path to the image file\n        output_size: the expected output size of each page in format H x W\n        rgb_output: whether the output ndarray channel order should be RGB instead of BGR.\n    Returns:\n        the page decoded as numpy ndarray of shape H x W x 3\n    \"\"\"\n\n    img = cv2.imread(file_path, cv2.IMREAD_COLOR)\n    # Resizing\n    if isinstance(output_size, tuple):\n        img = cv2.resize(img, output_size[::-1], interpolation=cv2.INTER_LINEAR)\n    # Switch the channel order\n    if rgb_output:\n        img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)\n    return img\n\n\ndef read_pdf(file_path: str, **kwargs: Any) -> List[np.ndarray]:\n    \"\"\"Read a PDF file and convert it into an image in numpy format\n\n    Example::\n        >>> from doctr.documents import read_pdf\n        >>> doc = read_pdf(\"path/to/your/doc.pdf\")\n\n    Args:\n        file_path: the path to the PDF file\n    Returns:\n        the list of pages decoded as numpy ndarray of shape H x W x 3\n    \"\"\"\n\n    # Read pages with fitz and convert them to numpy ndarrays\n    return [convert_page_to_numpy(page, **kwargs) for page in fitz.open(file_path)]\n\n\ndef convert_page_to_numpy(\n    page: fitz.fitz.Page,\n    output_size: Optional[Tuple[int, int]] = None,\n    rgb_output: bool = True,\n) -> np.ndarray:\n    \"\"\"Convert a fitz page to a numpy-formatted image\n\n    Args:\n        page: the page of a file read with PyMuPDF\n        output_size: the expected output size of each page in format H x W\n        rgb_output: whether the output ndarray channel order should be RGB instead of BGR.\n\n    Returns:\n        the rendered image in numpy format\n    \"\"\"\n\n    transform_matrix = None\n\n    # If no output size is specified, keep the origin one\n    if output_size is not None:\n        scales = (output_size[1] / page.MediaBox[2], output_size[0] / page.MediaBox[3])\n        transform_matrix = fitz.Matrix(*scales)\n\n    # Generate the pixel map using the transformation matrix\n    stream = page.getPixmap(matrix=transform_matrix).getImageData()\n    # Decode it into a numpy\n    img = cv2.imdecode(np.frombuffer(stream, dtype=np.uint8), cv2.IMREAD_UNCHANGED)\n\n    # Switch the channel order\n    if rgb_output:\n        img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)\n\n    return img\n", "path": "doctr/documents/reader.py"}]}