A comprehensive Java Spring Boot application that converts pictures of documents (specifically signup forms) into structured JSON format with batch processing capabilities, manual correction features, and field mapping functionality.
- OCR Processing: Advanced text extraction using Tess4J (Tesseract)
- Image Preprocessing: Automatic image enhancement using OpenCV
- PDF Support: Direct PDF text extraction and rendering
- Batch Processing: Process multiple documents simultaneously
- Manual Corrections: Web interface for correcting OCR results
- Field Mapping: Configurable mapping between form fields and JSON keys
- Progress Tracking: Real-time processing status updates
- REST API: Complete RESTful API with Swagger documentation
- Docker Support: Containerized deployment with PostgreSQL
- Java 17 - Modern Java with latest features
- Spring Boot 3.2 - Main application framework
- Spring Data JPA - Database operations
- Spring Security - Authentication and authorization
- Maven - Dependency management and build
- Tess4J - Java wrapper for Tesseract OCR
- OpenCV Java - Advanced image preprocessing
- Apache PDFBox - PDF handling and rendering
- PostgreSQL - Production database with JSON support
- H2 - Development and testing database
- Docker - Containerization
- Swagger/OpenAPI 3 - API documentation
- JUnit 5 - Testing framework
- Java 17+
- Maven 3.6+
- Docker (optional)
- Clone the repository
git clone <repository-url>
cd picture-to-json- Build the application
mvn clean package- Run the application
mvn spring-boot:runThe application will start on http://localhost:8080/api
- Build and run with Docker Compose
docker-compose up --buildThis will start both the application and PostgreSQL database.
POST /api/documents/upload- Upload a single documentPOST /api/documents/batch/upload- Upload multiple documentsPOST /api/documents/{id}/process- Start processing a documentPOST /api/documents/batch/process- Process multiple documents
GET /api/documents- Get all documents (paginated)GET /api/documents/{id}- Get document by IDGET /api/documents/status/{status}- Get documents by statusPUT /api/documents/{id}/correct- Apply manual corrections
PENDING- Document uploaded, waiting for processingPROCESSING- Currently being processedCOMPLETED- Processing completed successfullyFAILED- Processing failedCORRECTED- Manual corrections applied
Once the application is running, visit:
- Swagger UI:
http://localhost:8080/api/swagger-ui.html - OpenAPI JSON:
http://localhost:8080/api/api-docs
# Upload a document
curl -X POST "http://localhost:8080/api/documents/upload" \
-H "Content-Type: multipart/form-data" \
-F "file=@signup_form.jpg"
# Response: {"id": 1, "filename": "...", "status": "PENDING", ...}
# Start processing
curl -X POST "http://localhost:8080/api/documents/1/process"
# Check status
curl "http://localhost:8080/api/documents/1"curl -X PUT "http://localhost:8080/api/documents/1/correct" \
-H "Content-Type: application/json" \
-d '{"correctedJson": "{\"firstName\":\"John\",\"lastName\":\"Doe\",\"email\":\"[email protected]\"}"}'# Upload multiple files
curl -X POST "http://localhost:8080/api/documents/batch/upload" \
-H "Content-Type: multipart/form-data" \
-F "[email protected]" \
-F "[email protected]" \
-F "[email protected]"
# Process batch
curl -X POST "http://localhost:8080/api/documents/batch/process" \
-H "Content-Type: application/json" \
-d '[1, 2, 3]'- Images: PNG, JPG, JPEG
- Documents: PDF
Key configuration options in application.yml:
app:
upload:
directory: /tmp/picture-to-json/uploads # File storage location
ocr:
tesseract:
data-path: /tmp/tessdata # Tesseract data files
language: eng # OCR language
spring:
servlet:
multipart:
max-file-size: 50MB # Maximum file size
max-request-size: 100MB # Maximum request sizemvn testmvn clean package -Pproductiondefault- Development with H2 databasetest- Testing configurationproduction- Production with PostgreSQL
docker-compose updocker-compose -f docker-compose.yml -f docker-compose.prod.yml upGET /api/actuator/health- Application health status
- H2 Console:
http://localhost:8080/api/h2-console- JDBC URL:
jdbc:h2:mem:testdb - Username:
sa - Password: (empty)
- JDBC URL:
├── controller/ # REST API endpoints
├── service/ # Business logic
├── repository/ # Data access layer
├── entity/ # JPA entities
├── dto/ # Data transfer objects
├── config/ # Spring configuration
├── exception/ # Error handling
└── util/ # Utility classes
- Throughput: Process 100 documents in under 8 minutes
- Memory: < 2GB heap size for batch processing
- Startup: < 30 seconds application startup
- API Response: < 500ms for standard operations
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests
- Submit a pull request
This project is licensed under the MIT License.