Skip to content

add local pdf page extraction and text search tools - #6

Merged
OrellBuehler merged 1 commit into
mainfrom
pdf-page-tools
Aug 16, 2026
Merged

add local pdf page extraction and text search tools#6
OrellBuehler merged 1 commit into
mainfrom
pdf-page-tools

Conversation

@OrellBuehler

Copy link
Copy Markdown
Owner

Summary

Adds two tools that process a document's PDF locally in the MCP server, complementing the existing server-side editing tools (rotate_documents, edit_pdf_document, ...) which always modify the stored document:

  • extract_document_pages — downloads the PDF, extracts the requested pages (1-based, order preserved) with pdf-lib, and writes a new PDF to disk. Supports original: true to use the original file instead of the archived version. Errors clearly on out-of-range pages and non-PDF content.
  • find_document_pages — extracts per-page text with unpdf (Mozilla pdf.js) and returns the pages matching a case-insensitive, whitespace-normalized query, each with a snippet. Pairs with extract_document_pages to answer "give me just the page that mentions X" — Paperless's own full-text search has no page numbers.

Both are regular dependencies (pure JS, no native bindings), so unlike the embeddings stack they don't need the optional-dependency treatment.

Test plan

  • 7 new tests in src/__tests__/pdf-tools.test.ts build real PDFs with pdf-lib, stub client.download, and verify the request path, the written output PDF's page count, out-of-range/non-PDF errors, and text matching incl. the no-match case
  • format:check, lint, typecheck, and the full suite (144 tests) pass

🤖 Generated with Claude Code

extract_document_pages pulls pages out of a document's pdf into a new
file on disk (pdf-lib), and find_document_pages locates the pages
containing a text snippet via the pdf text layer (unpdf). both run
locally and never modify the document in paperless.
@OrellBuehler
OrellBuehler merged commit d83ac8f into main Aug 16, 2026
7 of 8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant