| 45 | |
| 46 | class PdfDocumentBackend(PaginatedDocumentBackend): |
| 47 | def __init__(self, in_doc: InputDocument, path_or_stream: Union[BytesIO, Path]): |
| 48 | super().__init__(in_doc, path_or_stream) |
| 49 | |
| 50 | if self.input_format is not InputFormat.PDF: |
| 51 | if self.input_format is InputFormat.IMAGE: |
| 52 | buf = BytesIO() |
| 53 | img = Image.open(self.path_or_stream) |
| 54 | img.save(buf, "PDF") |
| 55 | buf.seek(0) |
| 56 | self.path_or_stream = buf |
| 57 | else: |
| 58 | raise RuntimeError( |
| 59 | f"Incompatible file format {self.input_format} was passed to a PdfDocumentBackend." |
| 60 | ) |
| 61 | |
| 62 | @abstractmethod |
| 63 | def load_page(self, page_no: int) -> PdfPageBackend: |