Skip to main content

PDF table extraction with Docling and pdfplumber

Project description

pdf-kintsugi

pdf-kintsugi is a Python library that PDF table extraction and text recovery by combining the high-level document understanding of Docling with the precise, character-level bounding box analysis of pdfplumber.

Like the Japanese art of kintsugi (repairing broken pottery with gold), this library takes the initial parsing results from Docling and "repairs" complex table structures and text with garbled characters using pdfplumber's precise geometric layout analysis.

Features

  • Table Parsing: Improves Docling's table extraction by using pdfplumber to detect omitted geometric lines and infer table edges.
  • Text Correction: Optionally corrects garbled text using fine-grained character bounding boxes.
  • Seamless Integration with Docling: Acts as a post-processor for Docling. It takes a ConversionResult from Docling, enhances the tables and text in place, and returns the updated document model.

Installation

The project requires Python 3.10+.

You can install it using pip or your favorite package manager:

pip install pdf-kintsugi

Quick Start

pdf-kintsugi works alongside docling. Here is a basic example of how to use PDFKintsugi:

from docling.document_converter import DocumentConverter
from pdf_kintsugi import PDFKintsugi

pdf_path = "path/to/your/document.pdf"

# 1. Parse the document using Docling first
converter = DocumentConverter()
docling_result = converter.convert(pdf_path)

# 2. Initialize PDFKintsugi with the source PDF and the Docling result
kintsugi_parser = PDFKintsugi(
    source=pdf_path,
    docling_result=docling_result,
    tolerance=3.0,          # Adjust merging tolerance for table lines
    replace_text=False,     # Set to True to enable text/character correction
    replace_table=True      # Set to True to enable table structure repair
)

# 3. Get the parsing result
kintsugi_result = kintsugi_parser.parse()

# Now you can use kintsugi_result just like a regular Docling document
print(kintsugi_result.document.export_to_markdown())

Configuration

The PDFKintsugi class accepts several parameters to tune the extraction:

  • source (str): The file path to the source PDF document.
  • docling_result (ConversionResult): The parsed document object returned by Docling.
  • tolerance (float, default 3.0): The line-merging tolerance. A smaller value (e.g., 1.5) helps prevent adjacent tables from being incorrectly merged, while a larger value (e.g., 5.0) can help stitch together fragmented tables.
  • replace_text (bool, default False): If True, utilizes pdfplumber to extract characters and correct garbled text.
  • replace_table (bool, default True): If True, rebuilds and overrides the Docling table representations using geometric line intersections and edge inference.

Contributing

Contributions are welcome! This project uses uv for dependency management.

  1. Clone the repository.
  2. Setup the environment: uv sync
  3. Run tests before submitting a Pull Request.

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

pdf_kintsugi-0.1.2.tar.gz (18.0 kB view details)

Uploaded Source

Built Distribution

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

pdf_kintsugi-0.1.2-py3-none-any.whl (26.0 kB view details)

Uploaded Python 3

File details

Details for the file pdf_kintsugi-0.1.2.tar.gz.

File metadata

  • Download URL: pdf_kintsugi-0.1.2.tar.gz
  • Upload date:
  • Size: 18.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.9 {"installer":{"name":"uv","version":"0.9.9"},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for pdf_kintsugi-0.1.2.tar.gz
Algorithm Hash digest
SHA256 36de857f1e83b2336836aa0b1354a5a6a434a6dacf23553f96e605e455e0995e
MD5 40d15707496c9e1ae24cc302b6ba47f4
BLAKE2b-256 d37563ff8002c7fb0ca6255147e5fd5bf04bad18515b03b4333bc9f897ab06d4

See more details on using hashes here.

File details

Details for the file pdf_kintsugi-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: pdf_kintsugi-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 26.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.9 {"installer":{"name":"uv","version":"0.9.9"},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for pdf_kintsugi-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 34c1f03bf91edf0988fe8c957162ea5e1435afc5131af6df8b9ecff41f93f651
MD5 e124128c2f6bc025dc14627f127c460a
BLAKE2b-256 51ba1df489f1f9be48ade282e09c19285b1ad777606e99af5fd1d52169dedc57

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