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.5.tar.gz (5.4 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.5-py3-none-any.whl (5.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pdfalign-0.0.5.tar.gz
  • Upload date:
  • Size: 5.4 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.5.tar.gz
Algorithm Hash digest
SHA256 4e528ea8e45e64c5d4a08df1fafadab127412047228e219052f259fe50941400
MD5 1b574b7222ac8d77d5225d12c09cee35
BLAKE2b-256 3822b2bd42d5f9be9e742cd956ea03bf876bc55d670833404975e2538733c06c

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pdfalign-0.0.5-py3-none-any.whl
  • Upload date:
  • Size: 5.5 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.5-py3-none-any.whl
Algorithm Hash digest
SHA256 5184936ea66a56bff0c444db10d6abbc81219849c9e59dbb28d530828deca08e
MD5 2886953bd461a6b21afc5c8b35226343
BLAKE2b-256 84ffb0d6cb189feed16614ad7a71709a198f4097ebaba5f9e9a4b5c00fdd2695

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