Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions benchmark.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
pypdf_get_text,
pypdf_image_extraction,
pypdf_watermarking, tika_get_text, pdfium_image_extraction,
textract_get_text,
)
from pdf_benchmark.output import write_benchmark_report
from pdf_benchmark.score import get_text_extraction_score
Expand Down Expand Up @@ -218,6 +219,15 @@ def write_single_result(
last_release_date="-",
license="GPL",
),
"textract": Library(
"textract",
"textract",
"https://pypi.org/project/textract/",
text_extraction_function=textract_get_text,
version="2.0.0",
license="MIT",
last_release_date="2026-04-27",
),
# "borb": Library(
# "Borb",
# "borb",
Expand Down
13 changes: 13 additions & 0 deletions pdf_benchmark/library_code.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,19 @@ def pdfrw_watermarking(watermark_data: bytes, data: bytes) -> bytes:
return out_buffer.read()


def textract_get_text(data: bytes) -> str:
import textract
new_file, filename = tempfile.mkstemp(suffix=".pdf")
try:
with open(filename, "wb") as fp:
fp.write(data)
text = textract.process(filename).decode("utf-8", errors="replace")
finally:
os.close(new_file)
os.remove(filename)
return text


def tika_get_text(data: bytes) -> str:
from tika import parser

Expand Down
1 change: 1 addition & 0 deletions requirements/main.in
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ pymupdf
pypdfium2
pdfrw
lxml
textract