web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / Power Automate with Az...
Power Automate
Unanswered

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

(0) ShareShare
ReportReport
Posted on 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:
I have the same question (0)
  • Antoine2F Profile Picture
    Microsoft Employee on at

    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

     

  • avi2017 Profile Picture
    58 on at

    @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
    Microsoft Employee on at

    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 at

    @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
    Microsoft Employee on at

    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 at

    @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
    Microsoft Employee on at

    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 at

    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
    Microsoft Employee on at

    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)

     

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Users!

Kudos to our 2025 Community Spotlight Honorees

Congratulations to our 2025 community superstars!

Congratulations to the April Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Automate

#1
Vish WR Profile Picture

Vish WR 707

#2
Haque Profile Picture

Haque 475

#3
Valantis Profile Picture

Valantis 456

Last 30 days Overall leaderboard