[Python] Azure documen intelligence python SDK doesn't separate pages

Discussão em 'Python' iniciado por Stack, Fevereiro 28, 2025.

  1. Stack

    Stack Membro Participativo

    When trying to extract content from a MS Word .docx file using Azure Document Intelligence, I expected the returned response to contain a page element for each page in the document and for each of those page elements to contain multiple lines in line with the documentation.

    Instead, I always receive as a single page with no (None) lines and the entire document's contents as a list of words.

    Sample document: [​IMG]

    Minimal reproducible example:

    from azure.core.credentials import AzureKeyCredential
    from azure.ai.documentintelligence import DocumentIntelligenceClient
    from azure.ai.documentintelligence.models import DocumentAnalysisFeature, AnalyzeResult, AnalyzeDocumentRequest

    def main():
    client = DocumentIntelligenceClient(
    'MY ENDPOINT',
    AzureKeyCredential('MY KEY')
    )

    document = 'small_test_document.docx'

    with open(document, "rb") as f:
    poller = client.begin_analyze_document(
    "prebuilt-layout",
    analyze_request=f,
    content_type="application/octet-stream"
    )
    result = poller.result()

    print(f'Found {len(result.pages)} page(s)')
    for page in result.pages:
    print(f'Page #{page.page_number}')
    print(f' {page.lines=}')
    print(f' {len(page.words)=}')

    if __name__ == '__main__':
    main()


    Expected output:

    Found 2 page(s)
    Page #1
    page.lines=6
    len(page.words)=58
    Page #2
    page.lines=1
    len(page.words)=8


    Actual output:

    Found 1 page(s)
    Page #1
    page.lines=None
    len(page.words)=66


    My question is: Why, and what should I do differently to get the expected output?

    Continue reading...

Compartilhe esta Página