From 977fce3f023668810eca382200d2331d60b7d548 Mon Sep 17 00:00:00 2001 From: Kevin Turcios Date: Mon, 9 Nov 2026 03:17:08 -0500 Subject: [PATCH] perf(pdf): skip the per-character word walk for text boxes with no overlapping link --- unstructured/partition/pdf.py | 7 ++++--- unstructured/partition/pdf_image/pdfminer_processing.py | 7 ++++--- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/unstructured/partition/pdf.py b/unstructured/partition/pdf.py index f71523052d..d8da687802 100644 --- a/unstructured/partition/pdf.py +++ b/unstructured/partition/pdf.py @@ -673,9 +673,10 @@ def _pdfminer_page_elements( page_number, annotation_threshold, ) - _, words = get_words_from_obj(obj, height) - for annot in annotations_within_element: - urls_metadata.append(map_bbox_and_index(words, annot)) + if annotations_within_element: + _, words = get_words_from_obj(obj, height) + for annot in annotations_within_element: + urls_metadata.append(map_bbox_and_index(words, annot)) if hasattr(obj, "get_text"): # Use deduplication to handle fake bold text (characters rendered twice) diff --git a/unstructured/partition/pdf_image/pdfminer_processing.py b/unstructured/partition/pdf_image/pdfminer_processing.py index 580ad5f243..4c1c892618 100644 --- a/unstructured/partition/pdf_image/pdfminer_processing.py +++ b/unstructured/partition/pdf_image/pdfminer_processing.py @@ -501,9 +501,10 @@ def process_page_layout_from_pdfminer( page_number, annotation_threshold, ) - _, words = get_words_from_obj(obj, page_height) - for annot in annotations_within_element: - urls_metadata.append(map_bbox_and_index(words, annot)) + if annotations_within_element: + _, words = get_words_from_obj(obj, page_height) + for annot in annotations_within_element: + urls_metadata.append(map_bbox_and_index(words, annot)) if hasattr(obj, "get_text"): inner_text_objects = extract_text_objects(obj)