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.
Requesting help.
regards
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.
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)
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
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]
With your current logic, you can simply remove the "Final =" string at the beginning of GPT output to get the array.
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.
@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 .?
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.
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?
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 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
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.
Michael E. Gernaey
497
Super User 2025 Season 2
David_MA
436
Super User 2025 Season 2
Riyaz_riz11
244
Super User 2025 Season 2