import pdfplumber def extract_tables(pdf_path): table_chunks = [] with pdfplumber.open(pdf_path) as pdf: for page_num, page in enumerate(pdf.pages, start=1): tables = page.extract_tables() for table in tables: rows = [" | ".join(row) for row in table if row] table_text = "\n".join(rows) if table_text.strip(): table_chunks.append({ "page": page_num, "type": "table", "content": table_text }) return table_chunks