AI PDF Invoice Analyzer

AI-powered invoice processing system that extracts invoice data from PDF files using Google Gemini 2.5 Flash and stores the results in PostgreSQL.

Features

  • 📄 PDF Invoice Upload
  • 🤖 Gemini AI Data Extraction
  • 🗄 PostgreSQL Persistence
  • 📊 Excel Export
  • 📦 Multi PDF Upload Support

AI PDF Invoice Analyzer

AI-powered invoice processing system built with Spring Boot, Gemini API, PostgreSQL, and Apache POI.

Features

  • Upload PDF invoices
  • Extract invoice data using Gemini 2.5 Flash
  • Automatically identify:

    • Invoice Date
    • Seller Company Name
    • Product Description
    • Quantity
    • Unit Price
    • Total Amount
  • Store extracted data in PostgreSQL

  • Export invoice data to Excel (.xlsx)

  • Process multiple PDF invoices in a single request


Tech Stack

Backend

  • Java 17
  • Spring Boot
  • Spring Data JPA
  • PostgreSQL

AI

  • Google Gemini 2.5 Flash API

Document Processing

  • PDF Upload (MultipartFile)
  • Apache POI (Excel Export)

Architecture

PDF Upload
    ↓
Gemini API
    ↓
Invoice Extraction
    ↓
DTO Mapping
    ↓
PostgreSQL
    ↓
Excel Export

API Endpoints

Upload Invoice(s)

POST /api/invoices

Request:

multipart/form-data
files: invoice1.pdf
files: invoice2.pdf

Response:

[
  {
    "invoice_date": "28.04.2026",
    "seller_company_name": "Agrol LLC",
    "items": [
      {
        "product_description": "Frozen Whole Chicken",
        "quantity": 20000,
        "unit_price": 1.40,
        "total_amount": 28000
      }
    ]
  }
]

Get All Invoices

GET /api/invoices

Export Excel Report

GET /api/invoices/export

Downloads:

invoices.xlsx

Environment Variables

Create an environment variable:

GEMINI_API_KEY=YOUR_API_KEY

application.yml:

gemini:
  api-key: ${GEMINI_API_KEY}

Running Locally

Clone the repository:

git clone https://github.com/your-username/your-repository.git

Configure PostgreSQL.

Set your Gemini API key.

Run:

./gradlew bootRun

or

mvn spring-boot:run

Future Improvements

  • Invoice duplicate detection
  • ZIP file upload support
  • Invoice statistics dashboard
  • Company-based filtering
  • Docker support
  • Swagger/OpenAPI documentation
  • Batch processing with RabbitMQ
  • OCR fallback support

Author

Or Khan

Java Backend Developer Spring Boot | PostgreSQL | AI Integrations

Built With

Share this project:

Updates