← Catalog

pi-doc-reader

pi extension: read PDF/DOCX/XLSX/PPTX documents through the read tool — PDF text layer plus rendered page images for scanned pages, office documents converted to markdown.

Extension

Install

Install with PiG

pig install npm:pi-doc-reader

Install with Pi

pi install npm:pi-doc-reader
Review before installing

Packages run code with your permissions and influence agent behavior. Catalog inclusion is not a security audit. Review the source before installing a third-party package.

Pi manifest JSON

The pi field of package.json.

{
  "extensions": [
    "./index.ts"
  ]
}

README

Written by the package's publisher, shown as published in version 0.3.2 (README.md). PiG does not review it.

pi-doc-reader

npm version CI install with pi

A pi extension that lets the built-in read tool open office documents.

The extension overrides read (same-name tool registration, an officially supported mechanism). Files that are not office documents are delegated unchanged to the built-in implementation, so text and image behavior is byte-identical to stock pi.

Supported formats

FormatBehavior
PDFText layer extracted per page; pages with no text layer (scans) are rendered as PNG images for vision models (capped at 6 per call, longest side ≤ 1570px). Page through with the pages parameter ("1-10", "5-", "3,7"); default is the first 20 pages. Password-protected and unparseable PDFs get actionable fallback suggestions.
DOCXConverted to markdown: headings, lists, tables, inline formatting
XLSXConverted to markdown tables, one per sheet (formula results, rich text); rows/columns capped
PPTXSlides converted to markdown (title + body paragraphs, notes as a trailing section); media and layouts ignored
DOC/XLS/PPTLegacy OLE: suggests textutil / libreoffice conversion

Detection is content-based (magic bytes + zip central directory), so a DOCX renamed to .pdf still converts, and a text file renamed to .pdf still reads as text.

Conversions are cached by content hash under ~/.pi/agent/cache/pi-doc-reader/ (500MB, LRU-pruned): DOCX/XLSX markdown, PDF text-layer analysis, and rendered page PNGs. offset/limit apply to converted markdown for office documents; PDFs page with the pages parameter. On models without image input, scanned pages are skipped with a note and an OCR fallback suggestion.

Install

pi install npm:pi-doc-reader

Or from a checkout:

pi install /path/to/pi-doc-reader
# or one-off:
pi --extension /path/to/pi-doc-reader/index.ts

Configuration

Environment variables (all optional):

VariableDefaultMeaning
PI_DOC_READER_MODEoverridestandalone registers read_doc instead of overriding read
PI_DOC_READER_XLSX_ROWS50Max rows rendered per sheet
PI_DOC_READER_XLSX_COLS30Max columns rendered per sheet
PI_DOC_READER_PDF_MAX_IMAGES6Max scanned pages rendered as images per call
PI_DOC_READER_CACHE_DIR~/.pi/agent/cache/pi-doc-readerCache location

PDF page rendering uses @napi-rs/canvas prebuilt native binaries (macOS/Linux/Windows). If npm hits its optional-dependencies bug (npm/cli#4828) and the binding is missing, reinstall after removing node_modules and package-lock.json.

/doc-reader shows mode and cache usage; /doc-reader clear empties the cache.

Development

npm install --ignore-scripts
npm run typecheck
npm run test

TypeScript follows pi's erasable-syntax constraint (Node strip-only mode): no enums, namespaces, parameter properties, or import =.

License

MIT