A CPU-only OCR service built with FastAPI and PaddleOCR for text and table extraction from PDF, PNG, and JPG documents.
- Text Recognition: Extract text from documents using PaddleOCR with Russian language support
- Table Detection: Extract structured tables using PP-Structure
- Multiple Formats: Support for PDF, PNG, and JPG files
- Flexible Page Selection: Process specific pages with syntax like "1-3,5"
- Configurable DPI: Adjust PDF conversion quality
- HTML Output: Optional HTML representation of extracted content
- Health Check: Monitoring endpoint for service health
Health check endpoint that returns service status.
Response:
{
"status": "healthy",
"service": "PaddleOCR-API"
}Analyze documents for text and table extraction.
Parameters:
file(required): Document file (PDF, PNG, or JPG)dpi(optional, default: 350): DPI for PDF conversionpages(optional, default: all): Page specification like "1-3,5"return_html(optional, default: false): Include HTML representation
Response:
{
"lang": "ru",
"pages": [
{
"index": 1,
"text": {
"full": "Extracted text content..."
},
"tables": [
{
"rows": [
{"html": "<table>...</table>"}
],
"bbox": [x1, y1, x2, y2]
}
],
"html": "<div class='page'>...</div>"
}
]
}No need to build locally! Use the ready-to-go image:
docker run -p 8000:8000 bvdcode/paddleocrapi:v1.0The service will be available at http://localhost:8000
- Clone the repository (optional, only if you want to use docker-compose):
git clone https://github.com/bvdcode/PaddleOCR-API.git
cd PaddleOCR-API- Edit
docker-compose.ymlto use the prebuilt image:
services:
paddleocr-api:
image: bvdcode/paddleocrapi:v1.0
ports:
- "8000:8000"- Start the service:
docker-compose up- Build the image manually:
docker build -t paddleocr-api .- Run the container:
docker run -p 8000:8000 paddleocr-api- Install Python 3.12 and system dependencies:
# Ubuntu/Debian
sudo apt-get update
sudo apt-get install poppler-utils libgl1
# macOS
brew install poppler- Install Python dependencies:
pip install -r requirements.txt- Run the application:
python main.pyOr using uvicorn directly:
uvicorn main:app --host 0.0.0.0 --port 8000 --reload- FastAPI: Modern web framework for building APIs
- Uvicorn: ASGI server for FastAPI
- PaddleOCR: OCR toolkit with Russian language support
- PP-Structure: Table detection and structure analysis
- pdf2image: PDF to image conversion
- Pillow: Image processing library
- python-multipart: File upload support
curl http://localhost:8000/healthcurl -X POST "http://localhost:8000/analyze" \
-F "file=@document.pdf" \
-F "dpi=350" \
-F "pages=1-3,5" \
-F "return_html=true"curl -X POST "http://localhost:8000/analyze" \
-F "file=@image.png"The service can be configured through environment variables:
PYTHONUNBUFFERED=1: Ensure Python output is not bufferedPYTHONIOENCODING=utf-8: Set UTF-8 encoding for Python I/O
- CPU: Multi-core processor recommended
- Memory: Minimum 2GB RAM, 4GB+ recommended
- Storage: At least 2GB free space for models and temporary files
- OS: Linux, macOS, or Windows with Docker
- First request may take longer as PaddleOCR downloads required models
- PDF processing time depends on document size and page count
- CPU-only processing is slower than GPU but more compatible
- Consider using page selection for large documents to improve performance
This project is licensed under the MIT License - see the LICENSE file for details.
Contributions are welcome! Please feel free to submit a Pull Request.
For issues and questions, please create an issue in the GitHub repository.