Share via

Using Azure AI Document Intelligence, custom extraction model. How do I merge tables split over 2 pages?

Mischa de Queljoe 0 Reputation points
2025-10-30T14:09:44.5033333+00:00

I have tables in a pdf documents that get split up over pages. What to do with this? Online I can find code examples but anyway to this using the UI?

Azure Document Intelligence in Foundry Tools

1 answer

Sort by: Most helpful
  1. Sina Salam 30,166 Reputation points Volunteer Moderator
    2025-10-31T15:30:42.3366667+00:00

    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:

    1. Label each row of the table across pages using the same table tag.
    2. Ensure the table tag spans multiple pages.
    3. Use the Custom Neural Model (not Layout or Prebuilt) for best results.

    https://learn.microsoft.com/en-us/azure/ai-services/document-intelligence/concept-custom-label?view=doc-intel-4.0.0#tabular-fields

    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:

    1. Extract tables from each page.
    2. Use bounding box coordinates, table headers, and row continuity to detect and merge tables.
    3. 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
    

    https://learn.microsoft.com/en-us/samples/azure-samples/document-intelligence-code-samples/document-intelligence-code-samples/

    C. Best practice for the same:

    1. Use Custom Neural Model for flexible layout handling.
    2. Train with a balanced dataset:
      • Include single-page and multi-page table examples.
    3. Leverage spatial metadata:
    • Bounding boxes
    • Page numbers
      • Table headers

    https://learn.microsoft.com/en-us/azure/ai-services/document-intelligence/train/custom-model?view=doc-intel-4.0.0

    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.

    Was this answer helpful?

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.