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)