TablePatch proposes missing bottom borders in ruled, text-based PDFs and lets you compare the resulting extraction against the original page. It uses pdfplumber, keeps the source PDF unchanged, and retains unresolved cases for review.
Interactive demo · Batch example · Source repository
Use the linked demo, or download this repository and open docs/index.html in a browser. The HTML includes its data, scripts, styles, and four page previews, so it works offline without installing Python. The interface is in Chinese.
Select page 117 or 317, inspect the orange proposed border, and scroll to the last extracted row. Page 134 shows a case that remains unresolved. You can enter review notes and export them as JSON; import the exported file to restore the notes. Notes are held in memory until exported.
A missing bottom edge can cause text from several columns to appear in one extracted cell. TablePatch groups nearby vertical-line endpoints and checks column support, side anchors, and text placement before proposing a bounded horizontal edge. It passes the proposal to pdfplumber through explicit_horizontal_lines.
The tool compares the original cells outside the proposed region. If their bounding boxes or raw contents change, it withdraws the proposal. A proposal still needs inspection against the original page. The viewer keeps null, empty strings, and numeric strings such as 0.000 distinct.
The geometry implementation does not contain the example's page numbers, coordinates, or expected text. It uses a fixed tolerance of 3 PDF points. Existing manual coordinates appear only in the evaluation baseline.
The recorded local environment is Python 3.14.7 with pdfplumber 0.11.10. Install the pinned dependencies in a virtual environment:
python -m venv .venv
# Activate .venv using the command for your shell.
python -m pip install -r requirements-lock.txt
python launch.py your-file.pdf --pages 1,3-5The command creates a timestamped directory under runs/ and opens its review page. Start with a few pages: the viewer accepts at most 200 pages and 10 MB of report JSON. PDF parsing runs locally and does not upload the document.
On Windows, 打开工具.cmd starts an optional file-and-page picker. This requires Tkinter. The command-line processing chain was tested; the interactive file dialog has not been manually exercised.
For extraction without rendering:
python tablepatch.py your-file.pdf --pages 1,3-5 --output report.jsonRun the batch wrapper with the files you want to review:
python batch.py first.pdf second.pdf --pages 1,3-5 --output runs/review-batch --openThe same page selection applies to every input, with page 1 as the default. Pass --pages all to request every page. A batch accepts up to 100 files, with at most 200 selected pages and 100 MiB per file. Files with too few pages or invalid PDF data receive an error entry, and processing continues with the remaining inputs.
Open runs/review-batch/index.html to see the file statuses and follow each completed file's review link. manifest.json records inputs in the supplied order, their SHA256 values, and relative paths to the reports. The wrapper updates the manifest after each file and checks that the input hash still matches the generated report. Completion means the report was generated; proposals and unchanged results still require review.
The output directory must be new, including when rerunning a failed batch. Numbered subdirectories keep equal filenames and repeated inputs separate. Partial output from a failed file remains in its subdirectory for inspection, without a success link in the index. The command exits with code 1 if any file fails, 2 for invalid batch arguments, and 0 if every file completes. Move or share the entire batch directory to preserve its relative links.
The batch example is a saved run on three included synthetic PDFs. It demonstrates the local workflow; processing your own PDFs requires the CLI above. The wrapper reuses the frozen extraction core and adds no algorithm-accuracy claim.
| Scope | Default extraction | TablePatch proposals | Existing manual-coordinate method |
|---|---|---|---|
| Two development target rows in one real PDF, 36 raw slots | 4/36 matching | 36/36 matching | 36/36 matching |
| Eleven synthetic PDFs, 180 annotated slots | 150/180 matching | 175/180 matching | Not evaluated |
Five of six synthetic error cases meet the defined exact-content criterion, and all five negative controls remain unchanged. The scorer records extra blank frame rows separately and allows them under that criterion; exact content does not imply identical output matrix dimensions. The side-by-side-table case still has five incorrect slots. Real page 134 remains unresolved, while page 201 is an unchanged control without target-row ground truth.
The core was frozen before the first synthetic evaluation and was not tuned to the observed failure. A later scoring review added checks for extra columns and unexpected tables; the frozen-core recheck produced the same aggregate results. Initial and repeated evaluations remain in data/fixtures/evaluation_history.json.
The real target rows were checked against rendered source images. Source and preview hashes bind the ground truth, reports, and images to the same PDF. These are two development rows from one document, not an external test of general PDF accuracy. The 180 synthetic slots include normal rows and are not 180 independent samples.
The generated fixtures and saved results are included. The 6.8 MB real source PDF is downloaded separately to keep the repository small. After cloning, fetch that exact file once:
python fetch_sources.pyThe downloader tries the recorded GitHub attachment first, verifies its fixed size and SHA256, and preserves the original snapshot manifest. It also verifies an existing local copy. The download receipt is stored under ignored runs/. The interactive demo already embeds page previews and needs no PDF download.
Once the PDF and dependencies are present, reproduce the analysis offline:
python tablepatch.py data/source.pdf --pages 117,134,201,317 --output output/report.json
python prepare_review.py
python benchmark.py
python build.py
python -m unittest discover -s tests -vThe saved original local validation contains 37 passing Python tests and 10 passing browser checks. The Python suite covers geometry, actual fixture extraction, score boundaries, source binding, and safe HTML embedding. Repository preparation adds downloader checks, and the batch wrapper has separate integration tests for mixed failures, duplicate filenames, input changes, and stable manifests. GitHub Actions downloads and verifies the fixed PDF before running the current Python suite and rebuilding the saved demo. Current hosted results are available in the repository's Actions tab; output/batch-validation.json records the batch feature's local checks.
Optional browser checks:
npm install --ignore-scripts
npx playwright install chromium
npm run test:uiSet BROWSER_PATH to use an existing browser executable instead. QA_OUTPUT_DIR can redirect test logs and screenshots to another directory. Tests read the included examples and create temporary files under .qa/. The original browser record and screenshots remain in output/; output/batch-browser-validation.json records the later 12-check run, including batch navigation and mobile layout.
| File | Purpose |
|---|---|
tablepatch.py |
Frozen geometry heuristic, preservation checks, and extraction CLI |
launch.py |
Local PDF processing and rendering entry point |
batch.py |
Sequential multi-file processing, manifest, and batch review index |
build.py, web/ |
Self-contained review viewer |
benchmark.py |
Default, manual, and proposed extraction comparisons |
data/source-manifest.json |
Public source URLs, download record, and PDF SHA256 |
fetch_sources.py |
Download the separately stored PDF and verify its fixed hash |
data/real_ground_truth.json |
Two visually checked target rows |
data/fixtures/ |
Synthetic PDF generator, fixtures, plan, and evaluation history |
output/benchmark.json |
Per-case scores, extra rows, and unresolved cases |
output/validation.json |
Recorded environment, hashes, and test totals |
docs/batch/ |
Saved batch example generated from included synthetic PDFs |
output/batch-validation.json |
Batch feature tests and source integrity checks |
output/review.txt |
Implementation and evidence review |
The real example comes from pdfplumber issue #1370. A comment dated October 2, 2026 already provides manual coordinates for pages 117 and 317. TablePatch matches that method on the two target rows and automates the coordinate proposal; it does not claim to have discovered the workaround.
Discussion #631 covers missing bottom borders and explicit lines. Issue #1325 requests added borders for tables with missing outer edges. This repository implements and evaluates an engineering approach based on those existing ideas. It is a separate project and does not represent an accepted upstream fix.
Scanned-page OCR, cross-page table stitching, and arbitrary complex layouts are outside the evaluated scope. Additional real documents and the unresolved side-by-side case are useful next checks.
This is an AI-assisted personal project: the project owner commissioned the work, and AI performed implementation, case reproduction, testing, and documentation. No user-study or production-use results are claimed.
Source code is provided under the MIT license. Dependencies retain their licenses, and the public source PDF is not relicensed by this repository's code license. Its original source is recorded in data/source-manifest.json.
