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

PyPI PyPI - Downloads 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 align 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 pdfalign import align

# Extract grid aligned text from a pdf
# which returns a list for each pdf page
pages = align("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 pdfalign import align

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

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

You may refer to tutorial for more details

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.3.tar.gz (5.2 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.3-py3-none-any.whl (5.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pdfalign-0.0.3.tar.gz
  • Upload date:
  • Size: 5.2 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.3.tar.gz
Algorithm Hash digest
SHA256 1be9b83c87cb6e6fed386b39a2195acb7a588027d515d44cd7dd7508645b08d3
MD5 41b8271ab9f626bf55c0bb051faa6845
BLAKE2b-256 171a3e1d4324f4f0c8dabe5f795acc00f8a735220fdc23b2f7e7fa229f3e22d7

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pdfalign-0.0.3-py3-none-any.whl
  • Upload date:
  • Size: 5.3 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.3-py3-none-any.whl
Algorithm Hash digest
SHA256 458f7dc60c54fd4a3cc05112e5c92d26012bce4290a6594e43cbdf8d4bc2de7a
MD5 8cd78b91e0f6ae6de9dec11228705031
BLAKE2b-256 15e329dfc26ccd424d93a112646c5d45ebcd69a617a275fb230b167c05f4166c

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