Search code examples
azureazure-form-recognizer

Problem reading pdf file for azure form recognizer


I am very new to using Azure. I am trying to extract data from a pdf using Azure Form Recognizer built-in model. For that, I have taken the code from the Microsoft documentation for python and trying to implement in jupyter notebook. The pdf is in my local computer in the same directory where my .ipynb file is. But the problem is this line of code is not executing. Is it the correct way of specifying the pdf file or am I doing something wrong. Please help. Thanks in advace :)

form_recognizer = client.begin_recognize_content_from_url("test_file.pdf")

Solution

  • Try this :

    from azure.ai.formrecognizer import FormRecognizerClient
    from azure.core.credentials import AzureKeyCredential
    
    form_recognizer_client = FormRecognizerClient(endpoint='<endpoint>', credential=AzureKeyCredential('<key>'))
    
    filePath = "<file path>"
    
    f = open(filePath,'rb').read()
    
    result = form_recognizer_client.begin_recognize_content(f).result()
    print(result)
    

    Result:

    enter image description here