import fitz import re my_path = r"C:\Users\DELL\Downloads\A-24VU-00511.PDF.pdf" postal_code_pattern = r"(?0 else '' line_above = lines[i - 1] if i > 0 else '' line_below = lines[i + 1] if i + 1 < len(lines) else '' buyers.append({ 'line_2': line_2, 'line_above': line_above, 'postal_code_line': line, 'line_below': line_below }) print("Reference numbers:", order_numbers) print("Document dates:", order_dates) print("Buyers: ") for context in buyers: print("Company: ", context['line_2']) print("St. :", context['line_above']) print("City: ", context['postal_code_line']) print("Country:", context['line_below']) print()