Skip to content

Commit 4b51ba4

Browse files
committed
feat: accept playa.Document
1 parent ed4aec8 commit 4b51ba4

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

alexi/convert.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
import csv
44
import itertools
55
import logging
6-
from os import cpu_count
7-
from pathlib import Path
6+
from os import PathLike, cpu_count
87
from typing import Any, Dict, Iterable, Iterator, List, TextIO, Union
98

109
import playa
@@ -165,10 +164,13 @@ class Converteur:
165164
pdf: playa.Document
166165
tree: Union[Tree, None]
167166

168-
def __init__(self, path: Path):
167+
def __init__(self, pdf: Union[str, PathLike, playa.Document]):
169168
ncpu = cpu_count()
170169
ncpu = 1 if ncpu is None else round(ncpu / 2)
171-
self.pdf = playa.open(path, max_workers=ncpu)
170+
if isinstance(pdf, playa.Document):
171+
self.pdf = pdf
172+
else:
173+
self.pdf = playa.open(pdf, max_workers=ncpu)
172174
self.tree = self.pdf.structure
173175

174176
def extract_words(self, pages: Union[List[int], None] = None) -> Iterator[T_obj]:

0 commit comments

Comments
 (0)