Skip to main content

A modular OCR and PDF-processing toolkit for automated text extraction, deduplication, and multi-engine column-aware OCR using Tesseract, EasyOCR, and PaddleOCR

Project description


Abstract PDFs

PyPI version License: MIT Python Version

Abstract PDFs is a modular OCR and PDF-processing toolkit built for automation pipelines. It provides a structured way to ingest, deduplicate, split, and extract text from PDF documents — including column-aware OCR through multiple engines (PaddleOCR, EasyOCR, and Tesseract).

Designed to integrate seamlessly with other Abstract modules (like abstract_ocr and abstract_utilities), it forms the foundation for scalable document analysis, digital archiving, and machine learning dataset preparation.


Table of Contents


Architecture

`Architecture

This module is organized in a straightforward way. It consists of two main folders: 'pdf_utils', responsible for various PDF handling operations, and 'imports', managing the necessary import functions.

`

├── home
│   └── computron
│       └── Documents
│           └── pythonTools
│               └── modules
│                   └── src
│                       └── modules
│                           └── abstract_pdfs
│                               ├── abstract_pdfs
│                                  ├── AbstractPDFManager.py # Primary module for managing PDF operations                                  ├── SliceManager.py # Module for handling slice operations                                  ├── imports
│                                     ├── imports.py # General import functions used across the module                                     ├── manifest_utils.py # Utility functions for manifest handling                                  ├── pdf_utils
│                                     ├── imports.py # Import functions for PDF utilities                                     ├── pdf_to_text.py # Converts PDF files to text                                     ├── pdf_tools.py # Utility functions for PDF manipulation                                  ├── __init__.py # Initializer file for the abstract_pdfs module                               ├── __init__.py # Initializer file for the outer structure
│
└── # End of structure

The structure provided allows for modularity and separation of concerns. Each Python file serves a specific purpose, like converting PDFs to text, or managing PDF operations. This makes the module easy to maintain and extend.


Classes

Classes & API

The utilized classes and their key methods in this module are as follows:

  1. AbstractPDFManager: This class manages various PDF operations.

    • convert_pdf_to_image(): Converts PDF files to images.
    • extract_text_from_pdf(): Extracts text from PDF files.
    • split_pdf(): Splits a PDF into separate pages.
  2. SliceManager: This class handles slice operations.

    • generate_slices(): Generates slices from an image.
    • save_slices(): Saves the generated slices to a directory.
  3. PDFTools: This class contains utility functions for PDF manipulation.

    • merge_pdfs(): Merges multiple PDFs into a single PDF.
    • rotate_pdf(): Rotates pages in a PDF.
    • resize_pdf(): Resizes pages in a PDF.

These classes are designed to achieve modularity and separation of concerns, each serving a specific purpose like converting PDFs to text, splitting PDFs into separate pages, or managing slice operations. The methods contained within these classes provide easy access to the available functionalities of the module. The module encourages code reuse and simplifies complex tasks related to PDFs and image processing which ultimately makes it easy to maintain and extend.


Features

  • PDF to Image Conversion: Convert PDF files to images using the convert_pdf_to_image() method, which works with the PIL and pdf2image libraries.
  • Text Extraction from PDFs: Extract text from PDF files with the extract_text_from_pdf() method. The package relies on abstract_ocr for this functionality.
  • PDF Manipulation: Aggregate operations like splitting, merging, rotating, and resizing PDF files are possible using the split_pdf(), merge_pdfs(), rotate_pdf(), and resize_pdf() methods.
  • Slice Management: Generate and save slices from an image with generate_slices() and save_slices() methods. This feature is integral to the OCR process.
  • Modular Architecture: The architecture of this module is designed to be modular, which promotes code reuse and simplifies complex tasks related to PDFs and image processing.
  • Compatibility: The module requires Python 3.6 or higher, supporting compatibility with modern Python versions.

Installation

Prerequisites

The abstract_pdfs module requires Python 3.6 or higher for working compatibility. Also, make sure you have the following system libraries installed:

  • poppler-utils
  • tesseract

Installation with pip

You can install abstract_pdfs via pip.

pip install abstract_pdfs

Installation from source

If you prefer to install from the source, you can clone the repository and use pip to handle the installation:

# Clone the repository

git clone https://github.com/AbstractEndeavors/abstract_pdfs.git

# Navigate to the project directory

cd abstract_pdfs

# Install the package

pip install .

License and Summary

The abstract_pdfs module is released under the MIT License and is authored by putkoff. An abstract endeavor, this module enables powerful and flexible handling of PDF operations, ranging from conversion of PDFs into images, text extraction from PDF files, to a rich variety of aggregate operations like splitting, merging, rotating, and resizing PDF files.

For more information on this module, visit the official repository here. For other abstract projects, refer to the AbstractEndeavors Github page.


Overview

abstract_pdfs - Powerful PDF Handling for the Modern Python Developer - Version 0.0.0.001

Welcome to the documentation for the abstract_pdfs Python module. Authored by putkoff and maintained by AbstractEndeavors, this module is a part of a larger ecosystem of Python tools designed for tackling a host of programming challenges.

The primary purpose of abstract_pdfs is to provide developers with a powerful, flexible interface for managing PDF files. With dependency packages like PIL, abstract_ocr, and abstract_utilities, this module allows you to convert PDFs to images, extract text from PDFs, and perform various aggregate operations such as splitting, merging, rotating, and resizing PDF files.

The abstract_pdfs module fits within the broader Abstract ecosystem as a go-to solution for PDF management. Its functionality synergistically integrates with modules like abstract_ocr for optical character recognition, leveraging the power of the Abstract tools collection.

This module is in Alpha stage (Development Status 3) and is ready for integration by developers. It requires Python 3.6 or higher for optimal use. You will find further details on installation and features in the subsequent sections of this README.


Usage

Here is a basic python sample of how to use the abstract_pdfs module.

# Import required modules
from abstract_pdfs import PdfHandler

# Specify the required PDF file
path_to_pdf = "/path/to/your/pdf"

# Create an instance of PdfHandler
pdf_handler = PdfHandler(path_to_pdf)

# Now you can perform various operations like
# Converting PDF to Image
image_path = pdf_handler.to_image()

# Extract text from PDF
text = pdf_handler.extract_text()

# The extracted text will be in string format
print(text)

The abstract_pdfs module also comes with built-in support for handling multiple PDF files at once.

# Import required modules
from abstract_pdfs import PdfHandler

# Specify a list of PDF files
paths_to_pdfs = ["/path/to/your/pdf1", "/path/to/your/pdf2", "/path/to/your/pdf3"]

# Create instances of PdfHandler in a single line
pdf_handlers = [PdfHandler(path) for path in paths_to_pdfs]

# Now you can iterate over pdf_handlers to do various operations. For example:
for handler in pdf_handlers:
    # Print the number of pages in each PDF
    print(handler.number_of_pages)

These are just a few basic usage examples. The abstract_pdfs module exposes a rich API for manipulating and interrogating PDF files. Check out the API documentation for a full list of available methods and their descriptions.'


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

abstract_pdfs-0.0.13.tar.gz (31.3 kB view details)

Uploaded Source

Built Distribution

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

abstract_pdfs-0.0.13-py3-none-any.whl (33.6 kB view details)

Uploaded Python 3

File details

Details for the file abstract_pdfs-0.0.13.tar.gz.

File metadata

  • Download URL: abstract_pdfs-0.0.13.tar.gz
  • Upload date:
  • Size: 31.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.11

File hashes

Hashes for abstract_pdfs-0.0.13.tar.gz
Algorithm Hash digest
SHA256 eefd37dcb2805177ae2a2ad356e38e3a46d6d19acf895a114695cca6d0071478
MD5 007d47327052592c96fcbc1525d7a4ef
BLAKE2b-256 e32b2086693c0dfbc1c45001ce29542be2e8a761ef17aa8fb05caf4020a272ab

See more details on using hashes here.

File details

Details for the file abstract_pdfs-0.0.13-py3-none-any.whl.

File metadata

  • Download URL: abstract_pdfs-0.0.13-py3-none-any.whl
  • Upload date:
  • Size: 33.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.11

File hashes

Hashes for abstract_pdfs-0.0.13-py3-none-any.whl
Algorithm Hash digest
SHA256 05799abd646c89b49dd7383d3ff5a7eae39bb1e04152b0f61e6529a7aac1851a
MD5 2579473a39946039cba7dd8afa29c0c4
BLAKE2b-256 3b985ae0c6daaf32c9e6285197a19d984dadf9a4298507db19aa707317716d9e

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