Pixel-Perfect PDF Form and Worksheet Filling for AI Coding Agents.
Powered by Hybrid Vector-Raster Geometry, Set-of-Marks (SoM), and Virtual Excel Grounding.
Filling assignment worksheets, tax forms, and scanned PDF workbooks has always been a painful failure mode for Large Language Models (LLMs):
- β The "Floating Text" Bug: LLMs guess raw
(x, y)floats, causing answers to float aimlessly above or below lines. - β The "Collision" Bug: Answers smash directly into printed text (e.g.,
Heis going,Parentsmust,1)wear). - β The "Scanned PDF" Blindspot: Most PDF tools rely only on vector drawings. Scanned workbooks have 0 vector lines, leaving AI completely blind.
- β Multi-Line Truncation: Long answers get crammed into line 1 or truncated because the agent doesn't realize two lines are printed for that question.
Precision PDF solves this once and for all.
[ Input PDF: Digital or Scanned Workbook ]
β
βΌ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β 1. Tri-Layer Hybrid Detector β
β β’ Vector Lines & Rects (pdfplumber) β
β β’ In-Memory Morphological Line Scanner (NumPy) β
β Detects physical lines in scanned images in RAM! β
β β’ Text Anchors & Gap Numbers (1), 2., He_________) β
βββββββββββββββββββββββββββ¬ββββββββββββββββββββββββββββββββ
β
βΌ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β 2. Context Guards & Smart Layout β
β β’ Padding Guard: Auto +6pt..+10pt margin after β
β printed subjects (He, You, Jenny...) β
β β’ Multi-Line Grouping: Detects stacked lines & auto- β
β wraps long sentences at natural word boundaries β
β β’ Auto-Scale Font: Scales down font to prevent crash β
βββββββββββββββββββββββββββ¬ββββββββββββββββββββββββββββββββ
β
βΌ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β 3. Virtual Excel Matrix & Set-of-Marks (Agent View) β
β β’ Renders Top Columns (A, B, C...) & Rows (1, 2, 3) β
β β’ Badges targets: [S01], [S02], [S03]... β
β β’ STRICTLY VIRTUAL: Only for the agent to inspect! β
βββββββββββββββββββββββββββ¬ββββββββββββββββββββββββββββββββ
β
βΌ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β 4. Clean Vector Injection (Output PDF) β
β β’ Baseline Snapped: Text rests 1.2pt above line β
β β’ Centered in Boxes: Dead-center horizontally & vert β
β β’ Crisp Circles / Underlines: Vector option markers β
β β’ ZERO GRID POLLUTION: Output PDF is 100% clean! β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
No installation required. Run directly in Claude Desktop or Cursor via uvx:
uvx precision-pdf-mcppip install precision-pdf-mcpgit clone https://github.com/zuan412/precision-pdf-mcp.git
cd precision-pdf-mcp
pip install -e .Add to your claude_desktop_config.json:
macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
Windows: %APPDATA%\Claude\claude_desktop_config.json
{
"mcpServers": {
"precision-pdf": {
"command": "uvx",
"args": ["precision-pdf-mcp"]
}
}
}Add to Cursor Settings -> MCP Servers (~/.cursor/mcp.json):
{
"mcpServers": {
"precision-pdf": {
"command": "uvx",
"args": ["precision-pdf-mcp"]
}
}
}In your mcp_config.json:
{
"mcpServers": {
"precision-pdf": {
"command": "python",
"args": ["-m", "precision_pdf"]
}
}
}Generates a temporary Virtual Excel Matrix inspector image with Set-of-Marks badges ([S01], [S02]...) and returns a JSON catalog of detected slots.
- Arguments:
pdf_path(string, required): Absolute path to the PDF.page_number(int, required): 1-based page number.dpi(int, optional, default: 150): Image resolution.
- Returns:
inspector_image_path: Path to the image for agent visual inspection.slots: Dictionary of slots containing grid address (e.g.Col D, Row 14), type, baseline, and width.
Injects answers directly into the target PDF using Slot IDs.
- Arguments:
pdf_path(string, required): Absolute path to the PDF.page_number(int, required): 1-based page number.slot_answers_json(string, required): JSON string of answers.- Slot map:
{"S01": "must have left", "S02": "could do"} - Multi-line wrap:
{"S03": ["first line text", "second line text"]} - Option circle:
{"circle_option": "A"} - Option underline:
{"underline_option": "Shall"}
- Slot map:
output_path(string, optional): Output PDF path. If omitted, safely updates in-place.
- Guarantees:
- 100% baseline snap (rests naturally on the printed line).
- Zero grid pollution (no rulers or badges in final output).
Renders the final, clean PDF page to an image for visual QA verification.
- Arguments:
pdf_path(string, required): Path to the completed PDF.page_number(int, required): 1-based page number.dpi(int, optional, default: 150): Output DPI.
Run the included unit test suite:
python -m unittest discover -s testsPrecision PDF is engineered to run in memory:
- All morphological line detection and raster scanning execute in RAM via NumPy arrays and
io.BytesIO. - Temporary inspector previews use OS-standard
tempfile.gettempdir()/precision_pdfor the$PRECISION_PDF_TEMP_DIRenvironment variable. - Stdio JSON-RPC communication is 100% isolated: all logs, warnings, and internal debug outputs route strictly to
sys.stderr.
MIT License. See LICENSE for details. Built with β€οΈ for the AI agent pair-programming community.