An Azure service that turns documents into usable data. Previously known as Azure Form Recognizer.
Hello Mischa de Queljoe,
Welcome to the Microsoft Q&A and thank you for posting your questions here.
I understand that you are using Azure AI Document Intelligence, custom extraction model and would like to merge tables split over 2 pages.
Since you're already using Azure AI Document Intelligence with a Custom Extraction Model, this is how you can merge tables split across multiple pages, tailored to your setup in three methods:
A. Using UI-Based labeling in the Document Intelligence Studio.
Yes, you can merge tables across pages manually in the Studio:
- Label each row of the table across pages using the same table tag.
- Ensure the table tag spans multiple pages.
- Use the Custom Neural Model (not Layout or Prebuilt) for best results.
NOTE the limitation: This method is manual and may be error-prone if table structures vary significantly across pages.
B. Using SDK-BASED
Using the Python SDK, you can:
- Extract tables from each page.
- Use bounding box coordinates, table headers, and row continuity to detect and merge tables.
- Build logic to merge rows into a single unified table.
The below is a sample logic in Python:
from azure.ai.documentintelligence import DocumentAnalysisClient
from azure.core.credentials import AzureKeyCredential
client = DocumentAnalysisClient(endpoint, AzureKeyCredential(key))
with open("multi-page.pdf", "rb") as f:
poller = client.beginanalyzedocument("your-model-id", document=f)
result = poller.result()
mergedtable = []
lastheader = None
for page in result.pages:
for table in page.tables:
headers = [cell.content for cell in table.rows[0].cells]
if lastheader and headers != lastheader:
continue # Skip if headers don't match
lastheader = headers
rows = [[cell.content for cell in row.cells] for row in table.rows[1:]]
mergedtable.extend(rows)
# merged_table now contains all rows from matching tables across pages
C. Best practice for the same:
- Use Custom Neural Model for flexible layout handling.
- Train with a balanced dataset:
- Include single-page and multi-page table examples.
- Leverage spatial metadata:
- Bounding boxes
- Page numbers
- Table headers
I hope this is helpful! Do not hesitate to let me know if you have any other questions or clarifications.
Please don't forget to close up the thread here by upvoting and accept it as an answer if it is helpful.