Skip to main content

pdfalign is a very simple tool to grid align extracted pdf text. This is useful for invoice table extraction or further processing with llms / rag systems

Project description

pdfalign

GitHub

pdfalign is a very simple tool to extract text from a pdf in a grid aligned format. This is especially useful in table extraction pipelines. Some use cases include invoice data extraction and pdf processing for rag systems. The simple algorithm that pdfalign uses is the meanshift algorithm to group text blocks together and to algin grids. In some scenarios this may produce very sparse documents / tests. In most cases this is however not a problem for llms to handle

Features

  • Tesseract support: Can use tesseract automatically, if no text is detected on a pdf page.
  • Image support: Not only works with pdfs but also with for example scan copys of invoices.
  • Output as a pandas dataframe: One of the outputs is a pandas dataframe which can be used for further processing / transformations.

Installation

Install pdfalign using pip:

pip install pdfalign

Usage

Here's a quick example on how to use PDFalign to extract grid aligned text from a PDF file:

from pdfalgin import algin

# Extract grid algined text from a pdf
# which returns a list for each pdf page
pages = algin("sample.pdf", force_tesseract=False, tesseract_params=None)

for page in pages:
    print(page.text)
    print(page.dataframe)

If you want to use an Image you have to make sure that pytesseract is installed. Here is the code for that:

from pdfalgin import algin

# Initialize an Image object
img = Image("sample.jpg")

# Extract all tables from the image
# which returns a list of Table objects
text, dataframe = algin(img)

License

This project is licensed under the MIT License - see the LICENSE file for details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pdfalign-0.0.1.tar.gz (4.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pdfalign-0.0.1-py3-none-any.whl (4.9 kB view details)

Uploaded Python 3

File details

Details for the file pdfalign-0.0.1.tar.gz.

File metadata

  • Download URL: pdfalign-0.0.1.tar.gz
  • Upload date:
  • Size: 4.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.10.11

File hashes

Hashes for pdfalign-0.0.1.tar.gz
Algorithm Hash digest
SHA256 71ec8f03f6e3c760e90db9f1c24f93b81556a5559a66f36c300a021ebaf09bd6
MD5 cdb8a94a5cd0077f4e1cd44122eb5803
BLAKE2b-256 d61f52576cb10ec7998ac9ace8c80f2a213246f5fb11c2564aa31c60e8d82a74

See more details on using hashes here.

File details

Details for the file pdfalign-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: pdfalign-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 4.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.10.11

File hashes

Hashes for pdfalign-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 c4fee96e91f5dfa6a466ce286c8a072aac70d03e419e2cd73a91f59cd3cd5340
MD5 c20938acbcb4f0d23ed164d1646567ae
BLAKE2b-256 fad8d600e76644c1bf8aeb62e98463714991f3c9e1fafc487144b481bbd78c93

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page