Extract invoice number and invoice date from PDF invoices using Tesseract OCR (native C/C++ library) for image-based PDFs and OpenAI for smart parsing.
- Upload PDF invoices
- Smart text extraction:
- Direct PDF text extraction (no OCR) for machine-readable PDFs
- OCR fallback using Tesseract OCR for scanned/image-based PDFs
- AI-powered parsing with OpenAI
- Extracts:
- Invoice Number
- Invoice Date
- Clean UI with Inertia + React
- Easy to extend for more fields later
- Backend: Laravel 12
- Frontend: Inertia.js + React
- OCR Engine: Tesseract OCR (native C/C++ library)
- AI Parsing: OpenAI API
- Build Tooling: Vite
- PHP 8.3+
- Composer
- Node.js 18+
- Tesseract OCR (native C/C++ binary – required for scanned/image PDFs)
- OpenAI API Key (required)
⚠️ This project will not work without:
- Tesseract installed on your system
- A valid OpenAI API key
git clone https://github.com/levintoo/invoice-scan.git
cd invoice-ocrcomposer installnpm installcp .env.example .env
php artisan key:generateSet your OpenAI key:
OPENAI_API_KEY=sk-xxxxxxxxxxxxxxxxTesseract is a native C/C++ OCR engine. You must install it on your OS.
Linux (Ubuntu/Debian):
sudo apt install tesseract-ocrVerify:
tesseract --versionphp artisan serve
npm run devOpen:
http://localhost:8000
-
User uploads a PDF invoice
-
App first attempts direct text extraction from the PDF
-
If meaningful text is found → ➜ Text is sent directly to OpenAI (no OCR used)
-
If the PDF is scanned / image-based or text extraction fails → ➜ The document is passed through Tesseract OCR
-
Extracted text is sent to OpenAI
-
OpenAI returns structured data:
invoice_numberinvoice_date
-
Results are displayed in the UI
This approach avoids unnecessary OCR and speeds up processing for machine-readable PDFs.