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.1.tar.gz (18.2 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.1-py3-none-any.whl (26.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pdf_kintsugi-0.1.1.tar.gz
  • Upload date:
  • Size: 18.2 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.1.tar.gz
Algorithm Hash digest
SHA256 59a607357958fe2992855985902d01878ce05bfad0d9f0c1f1d050f635455ec1
MD5 d9ee71ba28f7dcbec8e566818bce524b
BLAKE2b-256 3b4cecd84da0d9d78869b788559f98a9d109c57d0a62b1039d24cd7a32dc7570

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pdf_kintsugi-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 26.1 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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 a9def94a21454a554399ab6814d8107a55bdf4f229b409fe6c94b8e6c2652000
MD5 2dc042fb7a65fde254478d4ba4eab959
BLAKE2b-256 f623a6e22144f87c6225a2f6f9bf2fc8d052258d84853755ed446a1d2b2bec79

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