Welcome to the Azure Document Analyzer Lab! This is a comprehensive, step-by-step learning experience that will guide you through building a web-based application using Azure AI Form Recognizer to analyze documents and extract structured data.
| Document | Description | Who It's For |
|---|---|---|
| OVERVIEW.md πΊοΈ | Visual learning path and lab structure | First-time visitors |
| README.md β | Main lab guide with step-by-step instructions | Everyone - main content! |
| QUICKSTART.md | 5-minute quick setup for experienced developers | Experienced developers |
| EXERCISES.md | Practice exercises and challenges | After completing main lab |
| FAQ.md | Frequently asked questions | When you need help |
| GLOSSARY.md | Terms and definitions | Reference as needed |
| CONTRIBUTING.md | How to improve this lab | Contributors |
| LICENSE | MIT License | Legal info |
π‘ Tip: New to this lab? Start with OVERVIEW.md to see the big picture, then come back here!
By the end of this lab, you will:
- β Create and configure an Azure Form Recognizer resource
- β Build a web application that analyzes PDFs and images
- β Extract key-value pairs, tables, paragraphs, and selection marks
- β Integrate Azure AI services into a JavaScript application
- β Deploy and test a document analysis solution
This project uses GitHub Actions for continuous integration and deployment:
-
CI Workflow: Runs on every pull request
- β Installs dependencies
- β Runs ESLint for code quality
- β Builds the project with webpack
- β Verifies build output
-
Deploy Workflow: Automatically deploys to GitHub Pages when changes are merged to
main- β Builds the application
- β Deploys to GitHub Pages
- β Makes your app publicly accessible
- Create a feature branch from
main - Make your changes and commit them
- Open a pull request for review
- CI automatically validates your changes
- After review and approval, merge to
main - Deployment automatically occurs to GitHub Pages
Once deployed, your application will be available at:
https://Sayan-dev731.github.io/document-analyzer/
To enable GitHub Pages deployment:
- Go to repository Settings > Pages
- Set Source to "GitHub Actions"
- Workflows will automatically deploy on merge to main
This lab is organized into progressive steps that build upon each other. Each step includes:
- Clear instructions with explanations
- Visual guides showing exactly what to do
- Code explanations to help you understand how it works
- Verification steps to ensure everything is working
Before you begin, make sure you have:
- Node.js (v14 or higher) - Download here
- Git - Download here
- Modern web browser (Chrome, Firefox, Edge, or Safari)
- Code editor (VS Code recommended) - Download here
- Azure Account with an active subscription
- Don't have one? Sign up for a free Azure account
- Free tier includes 500 pages/month for Form Recognizer!
Open a terminal and run these commands to verify your installations:
node --version # Should show v14.0.0 or higher
npm --version # Should show 6.0.0 or higher
git --version # Should show git version 2.0 or higherβ Checkpoint: All commands should return version numbers without errors.
In this step, you'll create an Azure Form Recognizer resource that provides the AI capabilities for document analysis.
- Open your browser and go to https://portal.azure.com
- Sign in with your Azure account credentials
- Click "Create a resource" (the β icon in the top-left corner)
- In the search bar, type "Form Recognizer" or "Document Intelligence"
- Select "Form Recognizer" from the results
- Click "Create"
Fill in the following details:
| Field | Value | Description |
|---|---|---|
| Subscription | Select your subscription | The Azure subscription to bill |
| Resource Group | Create new: document-analyzer-rg |
Logical container for your resources |
| Region | Choose closest to you | Where your service will be hosted |
| Name | my-document-analyzer |
Unique name for your service |
| Pricing Tier | Free F0 or Standard S0 | Free tier: 500 pages/month |
- Click "Review + Create"
- Review your settings
- Click "Create"
β±οΈ Wait time: 1-2 minutes for deployment to complete
Once deployment is complete:
- Click "Go to resource"
- In the left menu, click "Keys and Endpoint"
- You'll see:
- KEY 1 and KEY 2 (either one works)
- Endpoint URL
- Copy both values - you'll need them soon!
- Click the π copy icon next to KEY 1
- Click the π copy icon next to Endpoint
β Checkpoint: You should have:
- β A Form Recognizer resource deployed in Azure
- β An API key copied
- β An endpoint URL copied
Now let's get the project code and install its dependencies.
Open your terminal and run:
# Navigate to your preferred directory
cd ~/Documents # or wherever you keep your projects
# Clone the repository
git clone https://github.com/Sayan-dev731/document-analyzer.git
# Navigate into the project
cd document-analyzerTake a moment to understand what you have:
document-analyzer/
βββ src/
β βββ index.js # Main application logic (Azure integration here!)
βββ images/ # Lab screenshots and visual guides
βββ dist/ # Compiled JavaScript (generated by webpack)
βββ index.html # Main HTML page
βββ styles.css # Application styles
βββ image.png # Logo
βββ package.json # Node.js dependencies
βββ webpack.config.js # Webpack bundler configuration
βββ readme.md # This lab guide!
Run the following command to install all required packages:
npm installThis installs:
- @azure/ai-form-recognizer: Azure SDK for document analysis
- webpack: Module bundler to compile your code
- webpack-cli: Command-line interface for webpack
β±οΈ Wait time: 30-60 seconds
β Checkpoint: You should see:
- β
A
node_modules/directory created - β No error messages
- β Message like "added XXX packages"
Now it's time to connect your application to your Azure Form Recognizer service.
-
Open the project in your code editor:
code . # If using VS Code
-
Navigate to
src/index.js
Find these lines near the top of src/index.js:
const key = "paste-your-api-key-here";
const endpoint = "paste-your-endpoint-url-here";Replace them with YOUR credentials from Step 1.4:
const key = "YOUR_API_KEY_FROM_AZURE_PORTAL";
const endpoint = "YOUR_ENDPOINT_URL_FROM_AZURE_PORTAL";
// Example endpoint format: https://your-resource-name.cognitiveservices.azure.com/Let's understand what this code does:
// Import Azure SDK components
import {
AzureKeyCredential,
DocumentAnalysisClient,
} from "@azure/ai-form-recognizer";
// Your credentials (you just updated these!)
const key = "YOUR_API_KEY_HERE";
const endpoint = "YOUR_ENDPOINT_URL_HERE";
// Main function that analyzes documents
async function analyzeDocument(file) {
// 1. Create a client to communicate with Azure
const client = new DocumentAnalysisClient(
endpoint,
new AzureKeyCredential(key)
);
// 2. Start the analysis using the pre-built document model
const poller = await client.beginAnalyzeDocument("prebuilt-document", file);
// 3. Wait for the analysis to complete
const result = await poller.pollUntilDone();
// 4. Return the results
return result;
}What does "prebuilt-document" mean?
- Azure provides pre-trained models for common document types
- No training required - it works out of the box!
- Extracts: text, tables, key-value pairs, and more
- Store credentials in environment variables
- Use Azure Key Vault for secrets management
- Never commit credentials to Git
For this lab, we're using direct credentials for simplicity.
β Checkpoint:
- β
Your API key and endpoint are updated in
src/index.js - β File is saved
Now let's compile the application so it can run in your browser.
You can now use npm scripts to build the application:
# Build for production
npm run build
# Run linter to check code quality
npm run lint
# Run linter and auto-fix issues
npm run lint:fixOr use webpack directly:
npx webpackWhat's happening?
- Webpack reads your
src/index.jsfile - It bundles all the code and dependencies together
- It creates a single file:
dist/bundle.js - The HTML file loads this bundle to run your app
You should see output like:
asset bundle.js 119 KiB [emitted] (name: main)
webpack 5.97.1 compiled successfully in 2905 ms
Open webpack.config.js to see how it's configured:
import path from "path";
import { fileURLToPath } from "url";
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
export default {
entry: "./src/index.js", // Start from this file
output: {
filename: "bundle.js", // Create this output file
path: path.resolve(__dirname, "dist"), // In the dist folder
},
mode: "production", // Optimize for production
};β Checkpoint:
- β Build completed successfully
- β
dist/bundle.jsfile created - β No error messages
Time to see your document analyzer in action!
You can run the application in two ways:
Option A: Simple File Open
# Open the file directly in your default browser
open index.html # macOS
start index.html # Windows
xdg-open index.html # LinuxOption B: Local Web Server (Recommended)
# Install http-server globally (one-time setup)
npm install -g http-server
# Start the server
http-server
# Open browser to: http://localhost:8080You should see a clean, modern interface:
-
Click "Browse" to select a file
- Supported formats: PDF, JPEG, PNG, TIFF
- Maximum file size: 50 MB
-
Select a test document
- Use any PDF or image with text
- Invoices, receipts, and forms work great!
- If you don't have one, you can download sample forms from Azure samples
-
Click "Analyze Document"
-
Wait for results (usually 2-10 seconds depending on document size)
The application will display extracted information in a table:
You'll see:
| Data Type | What It Shows | Example |
|---|---|---|
| Key-Value Pairs | Labeled fields and their values | "Invoice Number: INV-12345" |
| Paragraphs | Text blocks identified in the document | Full sentences and paragraphs |
| Tables | Structured data in rows/columns | Price lists, line items |
| Selection Marks | Checkboxes and their states | β Selected or β Unselected |
| Confidence | AI's certainty (0.0 to 1.0) | 0.98 = 98% confident |
Problem: "Error: Invalid credentials"
- β
Double-check your API key and endpoint in
src/index.js - β Ensure there are no extra spaces
- β
Rebuild:
npx webpack
Problem: "Error: No file selected"
- β Make sure you clicked "Browse" and selected a file
Problem: "The bundle.js file is not loading"
- β
Check that
dist/bundle.jsexists - β
Run
npx webpackagain - β Hard refresh your browser (Ctrl+F5 or Cmd+Shift+R)
Problem: "CORS error"
- β Use a local web server (Option B above)
- β Don't open the HTML file directly from the file system
β Checkpoint:
- β Application opens in browser
- β You can upload a file
- β Document analysis completes successfully
- β Results are displayed in the table
Now that everything works, let's dive deeper into how the application functions.
<!-- File input for uploading documents -->
<input type="file" id="fileInput" accept=".pdf" />
<!-- Button to trigger analysis -->
<button id="analyzeButton">Analyze Document</button>
<!-- Results table (hidden until analysis completes) -->
<table id="resultsTable">
<tbody id="resultsBody"></tbody>
</table>document.getElementById("analyzeButton").addEventListener("click", async () => {
// 1. Get the selected file
const fileInput = document.getElementById("fileInput");
const file = fileInput.files[0];
// 2. Validate file was selected
if (!file) {
alert("Please select a file!");
return;
}
// 3. Show loading state
resultsBody.innerHTML = "<tr><td colspan='3'>Loading...</td></tr>";
try {
// 4. Convert file to Blob for Azure SDK
const fileData = new Blob([file], { type: file.type });
// 5. Call Azure to analyze the document
const analysisResult = await analyzeDocument(fileData);
// 6. Display the results
displayResults(analysisResult);
} catch (error) {
// 7. Handle any errors
resultsBody.innerHTML = `<tr><td colspan='3'>Error: ${error.message}</td></tr>`;
}
});The displayResults() function handles four types of extracted data:
1. Key-Value Pairs - Labeled information
result.keyValuePairs.forEach((kvp) => {
// kvp.key.content: "Invoice Date"
// kvp.value.content: "2024-01-15"
// kvp.confidence: 0.98
});2. Paragraphs - Text blocks
result.paragraphs.forEach((paragraph) => {
// paragraph.content: "This is a paragraph..."
// paragraph.confidence: 0.99
});3. Tables - Structured data
result.tables.forEach((table) => {
table.cells.forEach((cell) => {
// cell.content: Cell text
// cell.rowIndex: 0
// cell.columnIndex: 1
});
});4. Selection Marks - Checkboxes
result.selectionMarks.forEach((mark) => {
// mark.state: "selected" or "unselected"
// mark.confidence: 0.95
});Behind the scenes, here's what happens:
- Upload: Your document is sent to Azure (securely via HTTPS)
- OCR: Optical Character Recognition extracts all text
- Layout Analysis: AI understands document structure
- Entity Extraction: Identifies tables, key-value pairs, etc.
- Confidence Scoring: AI provides certainty levels
- Results: Structured JSON data is returned to your app
Want to add more features? Here are some ideas:
π¨ Visual Enhancements:
- Show bounding boxes on the original document
- Highlight extracted regions
- Add a document preview
π Data Export:
- Export results to CSV
- Generate a JSON download
- Create a PDF report
π Advanced Features:
- Use custom trained models for specific document types
- Add language detection
- Implement batch processing for multiple files
π‘οΈ Security Improvements:
- Move credentials to environment variables
- Add file size validation
- Implement rate limiting
Congratulations! π You've successfully completed the Azure Document Analyzer Lab!
β
Created an Azure Form Recognizer resource
β
Configured Azure credentials in your application
β
Built a document analysis web application
β
Tested document upload and analysis
β
Extracted key-value pairs, tables, and text
β
Understood how Azure AI services integrate with JavaScript
- Your application runs without errors
- You can upload and analyze documents
- Results display correctly with confidence scores
- You understand the code structure
- You can explain how the Azure SDK works
If you're done experimenting and want to avoid charges:
- Go to Azure Portal
- Navigate to your Resource Group:
document-analyzer-rg - Click "Delete resource group"
- Type the resource group name to confirm
- Click "Delete"
Note: The Free tier (F0) doesn't incur charges, so you can keep it running!
π Learn More About Azure AI:
π Enhance Your Project:
- Add support for invoices and receipts with specific models
- Create a backend API to keep credentials secure
- Deploy to Azure Static Web Apps
- Add user authentication
π€ Share Your Experience:
- Star this repository on GitHub β
- Share what you built on social media
- Help others by contributing to this lab
Issue: Build fails with "Module not found"
Solution: Delete node_modules and reinstall
rm -rf node_modules package-lock.json
npm install
Issue: "Access denied" or "401 Unauthorized"
Solution:
1. Verify your API key is correct (no extra spaces)
2. Check that the endpoint URL is complete
3. Ensure your Azure resource is deployed and active
Issue: "Quota exceeded"
Solution:
- Free tier: 500 pages/month limit
- Wait until next month or upgrade to Standard tier
- Check usage in Azure Portal under "Metrics"
Issue: Analysis takes very long or times out
Solution:
- Large PDFs (>10 MB) take longer
- Try a smaller document first
- Check your internet connection
- Verify Azure service status
Issue: No results or empty tables
Solution:
- Check the document quality (not too blurry)
- Ensure text is machine-printed (not handwritten) for best results
- Try a different document (invoice, receipt, form)
Need assistance? Here's how to get help:
- Check the Console: Open browser DevTools (F12) β Console tab
- Review Error Messages: Copy the full error for better debugging
- Azure Status: Check Azure Status Page
- Create an Issue: GitHub Issues
For Production Applications:
-
Never commit credentials
// β DON'T: Hard-code credentials const key = "actual-key-value-here"; // β DO: Use environment variables const key = process.env.AZURE_KEY;
-
Use Azure Key Vault for storing secrets
-
Implement a backend to proxy Azure calls
- Frontend calls your backend
- Backend holds credentials securely
- Backend calls Azure APIs
-
Add authentication to your app
-
Validate file uploads
// Check file size if (file.size > 50 * 1024 * 1024) { alert("File too large!"); return; } // Check file type const allowedTypes = ['application/pdf', 'image/jpeg', 'image/png']; if (!allowedTypes.includes(file.type)) { alert("Invalid file type!"); return; }
This project is licensed under the MIT License.
- Built with Azure Form Recognizer
- Powered by Azure AI services
- Created as an educational lab for learning cloud AI integration
Happy Learning! π
If you found this lab helpful, please β star the repository and share it with others!




