You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+19-27Lines changed: 19 additions & 27 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -314,22 +314,22 @@ Last updated: 2025-06-06
314
314
315
315
- Now we need to update the function code to extract data from PDFs and store it in Cosmos DB, use this an example:
316
316
317
-
> 1.**PDF Upload**: A PDF is uploaded to the Azure Blob Storage container.
318
-
> 2.**Trigger Azure Function**: The upload triggers the Azure Function `BlobTriggerContosoPDFInvoicesDocIntelligence`.
319
-
> 3.**Initialize Clients**: Sets up connections to Document Intelligence and Cosmos DB. <br/>
320
-
> - The function initializes the `DocumentAnalysisClient`to interact with Azure Document Intelligence. <br/>
321
-
> - It also initializes the `CosmosClient`to interact with Cosmos DB. <br/>
322
-
> 4.**Read PDF from Blob Storage**: The function reads the PDF content from the Blob Storage into a byte stream.
323
-
> 5.**Analyze PDF**: Uses Document Intelligence to extract data. <br/>
324
-
> - The function calls the `begin_analyze_document`method of the `DocumentAnalysisClient` using the prebuilt invoice model to analyze the PDF. <br/>
325
-
> - It waits for the analysis to complete and retrieves the results. <br/>
326
-
> 6.**Extract Data**: Structures the extracted data. <br/>
327
-
> - The function extracts relevant fields from the analysis result, such as customer name, email, address, company name, phone, address, and rental details. <br/>
328
-
> - It structures this extracted data into a dictionary (`invoice_data`). <br/>
329
-
> 7.**Save Data to Cosmos DB**: Inserts the data into Cosmos DB. <br/>
330
-
> - The function calls `save_invoice_data_to_cosmos` to save the structured data into Cosmos DB. <br/>
331
-
> - It ensures the database and container exist, then inserts the extracted data. <br/>
332
-
> 8.**Logging (process and errors)**: Throughout the process, the function logs various steps and any errors encountered for debugging and monitoring purposes.
317
+
> 1.**PDF Upload**: A PDF file is uploaded to the Azure Blob Storage container (`pdfinvoices`).
318
+
> 2.**Trigger Azure Function**: The upload triggers the Azure Function `BlobTriggerContosoPDFLayoutsDocIntelligence`.
319
+
> 3.**Initialize Clients**: Sets up connections to Azure Document Intelligence and Cosmos DB.
320
+
> - Initializes the `DocumentAnalysisClient`using the `FORM_RECOGNIZER_ENDPOINT` and `FORM_RECOGNIZER_KEY` environment variables.
321
+
> - Initializes the `CosmosClient`using Azure Active Directory (AAD) via `DefaultAzureCredential`.
322
+
> 4.**Read PDF from Blob Storage**: Reads the PDF content from the blob into a byte stream.
323
+
> 5.**Analyze PDF**: Uses Azure Document Intelligence to analyze the layout of the PDF.
324
+
> - Calls `begin_analyze_document`with the `prebuilt-layout`model.
325
+
> - Waits for the analysis to complete and retrieves the layout result.
326
+
> 6.**Extract Layout Data**: Parses and structures the layout data from the analysis result.
327
+
> - Extracts lines, tables, and selection marks from each page.
328
+
> - Logs styles (e.g., handwritten content) and organizes data into a structured dictionary.
329
+
> 7.**Save Data to Cosmos DB**: Saves the structured layout data to Cosmos DB.
330
+
> - Ensures the database (`ContosoDBDocIntellig`) and container (`Layouts`) exist or creates them.
331
+
> - Inserts or updates the layout data using `upsert_item`.
332
+
> 8.**Logging (Process and Errors)**: Logs each step of the process, including success messages and detailed error handling for debugging and monitoring.
333
333
334
334
- Update the function_app.py, for example [see the code used in this demo](./src/function_app.py):
- Since this function has already been tested, you can deploy your code to the function app in your subscription. If you want to test, you can use run your function locally for testing.
355
347
- Click on the `Azure` icon.
356
348
- Under `workspace`, click on the `Function App` icon.
@@ -360,13 +352,13 @@ Last updated: 2025-06-06
360
352
361
353
- Select your `subscription`, your `function app`, and accept the prompt to overwrite:
0 commit comments