harshankur/officeParser
A robust, strictly-typed Node.js and Browser library for parsing office files into a rich Abstract Syntax Tree (AST) and generating high-fidelity output in multiple formats. Parses: docx · pptx · xlsx · odt · odp · ods · pdf · rtf · csv · md · html. Generates: Markdown · HTML · CSV · RTF · PDF · Plain Text · RAG Chunks
Overview
officeParser is a Node‑compatible library that can read many common office‑document formats (like DOCX, PPTX, XLSX, PDF …) and turn them into a strictly‑typed abstract syntax tree (AST). The same AST can then be written back out to a wide range of target formats – DOCX, ODT, LaTeX, Markdown, HTML, CSV, RTF, PDF, EPUB‑…including RAG‑ready chunks for retrieval‑augmented generation pipelines.
The project ships both a programmatic API (for use in JavaScript/TypeScript code) and a CLI (npx officeparser …) for quick conversions on the command line. A browser‑based visualiser lets you upload a file, see the generated AST, tweak options and preview the output instantly.
Key Features
| Feature | What it does |
|---|---|
| Multi‑format parsing | Reads DOCX, PPTX, XLSX, ODT/ODP/ODS/ODG, PDF, RTF, CSV, Markdown, HTML, EPUB, LaTeX (including Overleaf zip projects) and produces a unified AST. |
| Multi‑format generation | From the AST you can emit DOCX, ODT, LaTeX, Markdown, HTML, CSV, RTF, PDF (native via pdf‑lib or Puppeteer), EPUB, plain text, or RAG‑chunks. |
| Native PDF engine | No headless browser needed – pdf-lib can create PDF bytes directly in Node or the browser. |
| Password handling | Single password/onPassword option works for encrypted PDFs, OOXML and ODF files. |
| Template / mail‑merge | OfficeTemplate.render fills {{placeholders}} in a DOCX/ODT template, supporting batch rendering. |
| OCR integration | Optional Tesseract‑based OCR on extracted images (useful for scanned PDFs or PPTX slides). |
| RAG chunking | Built‑in chunks output splits a document into retrieval‑ready pieces, with configurable size and overlap. |
| Fine‑grained config | Hundreds of CLI flags / TypeScript options control things like heading detection, column layout, colour extraction, image handling, LaTeX document class, etc. |
| Browser visualiser | Interactive web UI (/officeParser/) shows the AST tree, lets you edit config and preview generated files live. |
| Type‑safe API | Written in TypeScript; the AST and all public functions have strict typings. |
Typical Use‑Cases
| Scenario | How you would use officeParser |
|---|---|
| Extract plain text for indexing | await officeParser.parseOffice('file.pdf'); then await ast.to('text'); – the text respects original layout (columns, tables, headings). |
| Convert a Word doc to Markdown | CLI: npx officeparser report.docx --to=md --output=report.md or programmatically: await OfficeConverter.convert('report.docx', 'md'); |
| Generate a PDF from a DOCX without a headless browser | Set pdfConfig.engine: 'native' and call ast.to('pdf'). |
| Create a mail‑merge batch | Load a DOCX template, call OfficeTemplate.render([{name:'Alice'}, {name:'Bob'}]) to produce separate docs. |
| Feed documents into a Retrieval‑Augmented Generation pipeline | npx officeparser big_report.pdf --to=chunks or OfficeConverter.convert(file, 'chunks', {chunkingConfig:{maxTokens:500}}). |
| Process scanned PDFs | Enable --ocr (or ocr: true in code) together with extractAttachments – OCR runs on each extracted image and the recognised text becomes part of the AST. |
Getting Started
# Install the library
npm i officeparser # requires Node >= 22.13
Quick programmatic example (Node)
import { OfficeParser, OfficeConverter } from 'officeparser';
// Parse a DOCX file
const ast = await OfficeParser.parseOffice('proposal.docx', {
extractAttachments: true,
ocr: true, // run OCR on any embedded images
});
// Convert the same document to HTML
const html = await ast.to('html');
console.log(html.value);
// Or do a one‑step conversion
await OfficeConverter.convert('proposal.docx', 'pdf', {
pdfConfig: { engine: 'native' },
output: 'proposal.pdf',
});
CLI one‑liner
npx officeparser presentation.pptx \
--ocr --extractAttachments \
--to=html --output=preview.html
Limitations & Known Issues
- Very large PDFs can hit the default memory limits of the separate
pdf.jsprocess; increasepdfParserConfig.processMemoryMbif needed. - Text‑based formats (MD, HTML, CSV, TEX) need an explicit
fileTypewhen supplied as a raw buffer because they lack magic bytes. - The native PDF engine does not support advanced CSS‑based layout – for complex styling fall back to the
html(Puppeteer) engine. - OCR is CPU‑intensive and may be slow on large documents; it can be cancelled via an
AbortSignal.
License
MIT – free for commercial and personal use.
officeParser aims to be a one‑stop solution for developers who need to ingest, transform, or generate office‑style documents, especially when those documents feed downstream AI or RAG workflows.
Related
- Project
- Project
- Dispatch
- Dispatch
- Project