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
ConversionResultfrom 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, default3.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, defaultFalse): IfTrue, utilizespdfplumberto extract characters and correct garbled text.replace_table(bool, defaultTrue): IfTrue, 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.
- Clone the repository.
- Setup the environment:
uv sync - Run tests before submitting a Pull Request.
License
This project is licensed under the MIT License - see the LICENSE file for details.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pdf_kintsugi-0.1.0.tar.gz.
File metadata
- Download URL: pdf_kintsugi-0.1.0.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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5c4519c3d1f3c8fbc383cb321d6e97d008cd19747f0610db39a693ab5c547098
|
|
| MD5 |
f52a515aa320d47e86fdd056d65e17ca
|
|
| BLAKE2b-256 |
16ea05433d9052e4c84fc31d3c244e1078cb9a401a72073d97997ac1fe12b14d
|
File details
Details for the file pdf_kintsugi-0.1.0-py3-none-any.whl.
File metadata
- Download URL: pdf_kintsugi-0.1.0-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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a1c347fcfc726e5babea729416c213bfd52e4d8de30909d1f59ba3321fe06a6c
|
|
| MD5 |
95195fc89c389c26e83d74dafc1f5c4e
|
|
| BLAKE2b-256 |
0e6398212a21be2019c462ce3df4c928acd9bdfe5105e27a9eab2bd658822ec0
|