DSH PDF Toolbox: A Zero-Dependency PDF Parsing and Table Reconstruction Tool

Preface

The DeepSeek Harness (DSH) plugin ecosystem allows agents to directly invoke various capabilities. PDF processing is a common need: some PDFs have a text layer that can be extracted directly; some are scanned images requiring OCR; others contain tables that need structural reconstruction. Traditional solutions often depend on Python, LibreOffice, poppler, and other environments, making deployment complex and resource-intensive.

The @liubaibuliuyan/dsh-pdf-toolkit plugin introduced below turns PDF parsing capabilities directly into DSH agent tools — zero environment dependencies, on-demand loading, and a pure JavaScript implementation.

Plugin Overview

This plugin is developed by liubaibuliuyan and categorized under “Workflows.” It converts PDF documents into a set of tools, each responsible for a specific operation: metadata retrieval, per-page text extraction, page rendering, full-text search, bookmarks/outline, table geometric reconstruction, and scanned-page OCR.

The plugin bundles three npm packages: pdfjs-dist for parsing, @napi-rs/canvas for rasterization, and tesseract.js for OCR. These packages are loaded only when a tool is actually executed. During plugin startup, only registration occurs — no resources are consumed.

Seven Tools

Tool Purpose
pdf_info Page count, title, presence of text layer, which pages are scans, per-page text volume
pdf_text Per-page text extraction, preserving layout line breaks and reading order
pdf_render Render a page or specified rectangle to an image and inline it directly into the conversation so the model can see it immediately
pdf_search Full-text search, returning only hit pages and matched snippets
pdf_outline Bookmark/outline tree with starting page numbers
pdf_tables Table geometric reconstruction, outputting HTML with colspan or aligned text
pdf_ocr Scanned-page OCR (language packs downloaded on first invocation)

Zero Dependencies & On-Demand Loading

The plugin follows three design constraints:

  1. Zero environment dependencies. No Python, LibreOffice, poppler, CLI tools, or model files required. All dependencies are installed automatically by the host package manager per package.json.
  2. On-demand invocation. All packages are imported only when a tool is actually executed. The plugin loading phase only performs registration. If no tools are called, no resources are consumed, and the host startup is unaffected.
  3. Version independence. engines only declares node >= 20 without pinning a dsh version; aside from the optional @deepseek-ai/dsh-tools, no internal host modules are imported.

How Images Are Fed to the Model

pdf_render does not follow the “render to disk, then call read_image” path. Instead, it uses the host’s attachment channel to produce image content blocks directly:

  1. When pdf_render executes, it first rasterizes the page to PNG
  2. Retrieves the attachment store via ctx.get('attachments'), then saveImages() converts it back to ImageAttachmentRef
  3. output.render returns [{type:'text'}, {type:'image', attachment}, ...]
  4. The model sees it at this step — no additional tool call needed

It first calls llm.resolveModelInfo() to confirm the current model declares image as an input modality. If unsupported, it automatically degrades to returning only the file path with a hint to use read_image instead — a failure in the image channel won’t crash the tool itself.

Table Geometric Reconstruction

Table reconstruction is purely geometric — no model involved:

  1. Group text items into rows by y-coordinate
  2. Group rows using column alignment features — rows belonging to the same table necessarily share consistent x-start positions per column; body paragraphs have random line-break positions and naturally fail this criterion
  3. Absorb multi-line headers and vertically oriented titles via column anchors
  4. Slice columns only from data rows (header colspan items bridge gaps and must be excluded)
  5. Compute colspan based on each item’s x-range coverage
  6. Three filters to suppress false positives: minimum 3 rows, exclude A./B./C./D. option columns, require cells to be short and predominantly numeric

Benchmark results: 29-page full scan in 107 ms; a thermocouple calibration table reconstructed as 11 columns × 10 rows, with every cell value matching the PDF source exactly.

Performance

Measured on the same 29-page review question set:

Operation Duration
pdf_info full document 113 ms
pdf_text full document 103 ms
pdf_tables full scan 107 ms
pdf_search full document 108 ms
pdf_render single page 144 ms
Cold start (first pdfjs load) 281 ms
Peak memory 296 MB

Known Limitations

  • Table rowspan is not yet reconstructed (colspan is supported)
  • Formulas are extracted at the text level only, not converted to LaTeX — use pdf_render with zoom for precise structural inspection
  • Scanned-page OCR uses tesseract, which is weaker for Chinese than dedicated OCR models
  • Two-column layouts are read in geometric order without semantic column detection

Installation

Install from GitHub Release (recommended):

Download dsh-pdf-toolkit-<version>.tgz from the latest Release, then:

dsh plugin --profile <profile> add <download-path>/dsh-pdf-toolkit-1.0.0.tgz

Install from source:

dsh plugin --profile <profile> add github:liubaibuliuyan/dsh-pdf-toolkit

Local development:

"dependencies": {
  "@liubaibuliuyan/dsh-pdf-toolkit": "link:D:/aitest/plugins/dsh-pdf-toolkit"
},
"dsh": { "profile": { "bundles": [ "...", "@liubaibuliuyan/dsh-pdf-toolkit" ] } }

Restart DSH after installation. The three dependencies (pdfjs-dist / @napi-rs/canvas / tesseract.js) are installed automatically by the host package manager per package.json — no additional environment setup needed.

Typical Usage

  1. pdf_info → 29 pages, has text layer, pages 5 and 21 are scans
  2. pdf_text pages:"1-3" → read the first three pages of body text
  3. pdf_tables pages:"20" → reconstruct the calibration table
  4. pdf_render pages:"7" scale:3 → render the full page to inspect illustrations
  5. pdf_render pages:"7" region:"60,260,540,420" scale:4 → zoom into just the illustration area

Use Cases & Cautions

Suitable for scenarios requiring direct PDF processing within a DSH agent: extracting document content, searching specific paragraphs, reconstructing table structures, inspecting illustration details, and handling scanned pages.

The plugin runs with the current dsh process permissions. Review the source code and license (MIT) before installing.

Closing Remarks

The DSH philosophy is “everything is a plugin.” The community plugin directory is an independent site with no official affiliation to DeepSeek or High-Flyer.

Plugin directory: https://www.skillhub.cn/plugins/liubaibuliuyan/dsh-pdf-toolkit

GitHub: https://github.com/liubaibuliuyan/dsh-pdf-toolkit

羽毛球分组比赛记分
小程序二维码

欢迎使用《羽毛球分组比赛记分》微信小程序

Xiaoye