Skip to main content
Community site session details

Community site session details

Session Id :
Power Automate - AI Builder
Unanswered

Power Automate with Azure OpenAI Service and Recognize text in an image or a PDF document

Like (0) ShareShare
ReportReport
Posted on 2 Jun 2023 21:28:03 by 58

Hello Gurus

 

I have a PDF document ( Scanned PDF ) with 10 plus pages. I want to extract data from PDF and convert to TABULAR form with fixed columns . I have attached the flow that I created . Apply to Each Page and Apply to Each text is not working correctly . I have to loop through pages and call  Azure OpenAI Service because of the character restriction . Finally I have to write the data into an excel file.

 

POWERAUTOMATE.jpg

Requesting help.

 

regards

 

 

Categories:
  • Antoine2F Profile Picture
    on 07 Jun 2023 at 15:36:59
    Re: Power Automate with Azure OpenAI Service and Recognize text in an image or a PDF document

    If I understand correctly, you have an array variable, and you want to write it into a csv file.

     

    You need a loop to build the content (string) of your csv.

    Antoine2F_0-1686151844307.png

    GPT prompt : Generate a csv output out of following text (without header)

     

    Expression of 'Append to stringResult variable': concat(variables('itemData'),variables('newLine'))

    (newLine was initiated to "

    ") 

     

    Note : you could have built this content (string) directly in the original loop instead of building an array. (use append to string action, and concat the output of GPT with a newLine)

     

  • avi2017 Profile Picture
    58 on 07 Jun 2023 at 12:02:27
    Re: Power Automate with Azure OpenAI Service and Recognize text in an image or a PDF document

    Antonie

     

    This is what I pass into GPT, I have to split text into chunks and call GPT multiple times . After each GPT call I am appending the output of GPT into an Array. What is your suggestion to get the final data to be written into a CSV file  

    Prompt.jpg

    Convert below text into tabular form with columns HOLDER,OPERNO,ORDERNO,WELL,LEGALDESC,COUNTY,OWNERNAME and append to Array Final. Consider all OWNERNAMES into one column OWNERNAME seperated by coma .Remove handwritten text.
    [Start of text]
    @{variables('ExtractedText')}
    [End of text]

  • Antoine2F Profile Picture
    on 07 Jun 2023 at 10:02:57
    Re: Power Automate with Azure OpenAI Service and Recognize text in an image or a PDF document

    With your current logic, you can simply remove the "Final =" string at the beginning of GPT output to get the array.

    Assuming gpt Text is put in gptoutput variable, Expression would be: 
    replace(variables('gptoutput'),'Final =','')​
    Then add a GPT action to convert it to HTML.

    But if what you need is html table, you should ask GPT to provide the data as HTML in the first place instead of getting it in tabular form.

     

    Hope this helps. 

  • avi2017 Profile Picture
    58 on 06 Jun 2023 at 21:04:42
    Re: Power Automate with Azure OpenAI Service and Recognize text in an image or a PDF document

    @Antoine2F Thanks for the suggestion . In the GPT prompt I mentioned "convert the below text to tabular form with columns A,B,C,D and append to Array variable Final

     

    Question : How do I use array FINAL at the end of the processing and convert to an HTML tables .?

  • Antoine2F Profile Picture
    on 06 Jun 2023 at 10:27:18
    Re: Power Automate with Azure OpenAI Service and Recognize text in an image or a PDF document

    GPT Action output is a Text. You can use this Text (Dynamic Content) as an input for following actions like set a variable, or write a file. 

    You can also use it as an input for a second request to GPT to transform it into an HTML table.

     

  • avi2017 Profile Picture
    58 on 06 Jun 2023 at 03:07:06
    Re: Power Automate with Azure OpenAI Service and Recognize text in an image or a PDF document

    @Antoine2F 

    I was able to set the prompt , Get data in tabular form and append the data into Array . 

    I can see the array in GPT output. Is there a way to get the Array data outside of GPT prompt so I can write to an HTML table?

  • Antoine2F Profile Picture
    on 05 Jun 2023 at 13:36:39
    Re: Power Automate with Azure OpenAI Service and Recognize text in an image or a PDF document

    Question 1 : Yes, it seems you have to split your query. (for instance for first 100 pages, then next 100 pages.) Or you can reduce the size of the answer. I would expect the answer to be smaller than the request in your context.

    Question 2:  An idea is to request the output of GPT to be in csv format, then you create a csv file out of it.

    Antoine2F_0-1685972178199.png

     

  • avi2017 Profile Picture
    58 on 05 Jun 2023 at 12:43:52
    Re: Power Automate with Azure OpenAI Service and Recognize text in an image or a PDF document

    @Antoine2F PDF data is "not" structured in table format. 

    Thanks for the suggestion on Apply to Each .

     

    Question 1 : Now am getting below error . Does this mean I will have to split the text into may be like 1500 characters and call "Create text with GPT on Azure OpenAI service" for every 1500 characters or so ( number 1500 is just an example am using ) ?

     

     

    {"operationStatus":"Error","error":{"type":"Error","code":"InvalidPredictionInput","message":"Error during call to Azure OpenAI Completions API. Invalid prompt input. This model's maximum context length is 4097 tokens, however you requested 4105 tokens (563 in your prompt; 3542 for the completion). Please reduce your prompt; or completion length..","properties":{"BackendErrorCode":"InvalidInferenceInput","DependencyHttpStatusCode":"400"},"innerErrors":[{"scope":"Generic","target":null,"code":"TooManyInputTokens","type":"Error","properties":{"MlIssueCode":"TooManyInputTokens"}}]},"predictionId":null}

     

    Question 2 : How to append the output of "Create text with GPT on Azure OpenAI service" into a table or Array and finally write the data to excel ?

    Each time the out put of Create text with GPT on Azure OpenAI service will be as below 

     

    PAGENO | HOLDER | OPERNO | ORDERNO | WELL | LEGALDESC | COUNTY | PERSONNAME
    1      | MS CORPORATION CO LP | 20751 | 562345 | FORD BRONCO | 200-M-400N | EDDY | JAMESON ANTONY,SPRINKLER SUBWAY
    2      | JUNIPER CORP | 30000 | 538621 |JERMIA 3450 | 14-12N-10W IM | KINGFISHER | NLS PEARSON, EDWARD  SUMMIT 
  • Antoine2F Profile Picture
    on 05 Jun 2023 at 09:16:41
    Re: Power Automate with Azure OpenAI Service and Recognize text in an image or a PDF document

    Hello,

    Is your pdf data structured in tables? If yes, then you could use a 'Document processing' custom model.

     

    Assuming it's plain text, then your double loop seems right. Make sure that in the settings of both 'Apply to each', you set concurrency control On with Degree of Parallelism set to 1, so that your string is built in order, one line after the other.

    Once you've extracted the complete text of the pdf, you can us it within a  'Create text with GPT' action, but it should be outside of the double loop.

    Antoine2F_0-1685956482404.png

     

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Paul Stork – Community Spotlight

We are honored to recognize Paul Stork as our July 2025 Community…

Congratulations to the June Top 10 Community Leaders!

These are the community rock stars!

Announcing the Engage with the Community forum!

This forum is your space to connect, share, and grow!

Leaderboard > Power Automate

#1
Michael E. Gernaey Profile Picture

Michael E. Gernaey 497 Super User 2025 Season 2

#2
David_MA Profile Picture

David_MA 436 Super User 2025 Season 2

#3
Riyaz_riz11 Profile Picture

Riyaz_riz11 244 Super User 2025 Season 2