Sign inSign up

truongginjs/pdf-table-extractor

By truongginjs

Updated about 1 year ago

FastAPI endpoint to upload PDF and extract tables with 'color' column as JSON.

Image
0

438

truongginjs/pdf-table-extractor repository overview

PDF Table Extractor

This project exposes a FastAPI endpoint to upload a PDF and extract the table that contains a "color" column as JSON.

Quickstart

  1. Create a virtualenv and install dependencies:
python -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt
  1. Run the server:
uvicorn app:app --reload --host 0.0.0.0 --port 8000
  1. Upload a PDF using the provided upload agent:
python upload_agent.py sample.pdf

Notes

  • Requires Java for tabula-py to work (Tabula uses a Java backend). Make sure java is on your PATH.
  • If tables aren't detected correctly, try adjusting tabula.read_pdf parameters or using lattice=True / stream=True.

Docker Usage

This project is available as a Docker image on Docker Hub.

Pull the Image
docker pull truongginjs/pdf-table-extractor:1.0
Run with Docker
docker run -p 8000:8000 truongginjs/pdf-table-extractor:1.0

The API will be available at http://localhost:8000.

Run with Docker Compose
docker-compose up

This will build and run the service with volume mounting for development.

API Endpoints

  • GET /: Get API information.
  • POST /extract: Upload a PDF and extract the table containing a "color" column as JSON.
  • POST /extract-all-table: Upload a PDF and extract all tables as JSON arrays.
Usage Example

Upload a PDF using curl:

curl -X POST "http://localhost:8000/extract" -F "[email protected]"

Or use the provided upload agent:

python upload_agent.py sample.pdf

Building Locally

If you prefer to build the image locally:

docker build -t pdf-table-extractor .
docker run -p 8000:8000 pdf-table-extractor

Tag summary

Content type

Image

Digest

sha256:f332e5846

Size

267 MB

Last updated

about 1 year ago

docker pull truongginjs/pdf-table-extractor