pdf-parse

Pure TypeScript PDF parser for extracting text, images, tables, and metadata in Node.js and browsers.

Library
npm
v2.4.5
225 stars
Apache License 2.0

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum. How we score it →
36 /100 Needs Attention
Development Activity 4
Maintenance 32
Community 32
Maturity 36
Momentum 40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation. How we score it →
86 /100 Excellent
Architecture 82
Code Quality 85
Innovation 78
Learning Curve 100

pdf-parse is a pure TypeScript library built on Mozilla’s pdfjs-dist for extracting text, images, tables, and document metadata from PDF files. It runs identically in Node.js, browsers, and web workers, exposing a single PDFParse class with dedicated methods for header validation, metadata extraction, plain text and paragraph reconstruction, page-rendering to PNG, embedded image extraction, and table detection.

The library ships as CJS and ESM builds with full TypeScript typings, a Node-only submodule for lightweight header checks via range requests, and an optional canvas-based renderer for image and screenshot output. A companion command-line interface wraps the same functionality for scripted batch processing without writing any code, and the project publishes typed exceptions (PasswordException, InvalidPDFException, and others) so callers can handle protected or malformed PDFs explicitly.

What You Get

  • A single PDFParse class covering header checks, metadata, text, paragraphs, screenshots, images, and tables
  • CJS, ESM, and browser builds published from one codebase with matching TypeScript declarations
  • A global CLI (pdf-parse) for extracting text, images, or tables from the terminal without writing code
  • Typed exception classes (PasswordException, InvalidPDFException, FormatError, and more) for precise error handling
  • A Node-only getHeader() helper that validates PDF magic bytes and reads file size via a lightweight HTTP range request before downloading the full file

Common Use Cases

  • Extracting searchable text from uploaded PDFs in a Next.js or Node.js API route
  • Generating page thumbnails or full-page PNG screenshots for a PDF viewer UI
  • Pulling structured tables out of invoices or reports for downstream data processing
  • Validating a remote PDF URL’s size and signature before committing to a full download

Under The Hood

Architecture

The core class PDFParse (src/pdf-parse/PDFParse.ts) wraps pdfjs-dist’s PDFDocumentProxy, exposing typed methods (getHeader, getInfo, getText, getScreenshot, getImage, getTable) that each operate on a lazily-loaded document and return typed Result classes (TextResult, ImageResult, ScreenshotResult, HeaderResult, InfoResult) defined as separate files under src/pdf-parse/. The package is split into independent build targets — src/pdf-parse (shared core), src/node (Node-only helpers like the range-request logic behind getHeader), src/worker (web worker glue with canvas support), and a pro entry point referenced in the exports map — each compiled by its own Vite/Rolldown/tsconfig pipeline and published as parallel CJS/ESM/browser bundles under one exports map. This is a modular, single-responsibility-per-file layered design: PDFParse is the single façade, Result classes hold data plus convenience accessors such as getPageText, and Exception.ts centralizes typed error translation from pdfjs-dist’s internal errors.

Tech Stack

pdfjs-dist is the core PDF rendering engine, consumed via pdfjs-dist/legacy/build/pdf.mjs; @napi-rs/canvas is an optional native dependency for server-side canvas rendering of screenshots and images, explicitly disabled in browser builds via the package’s browser field. Build tooling combines Vite and Rolldown (a Rust-based bundler) for the browser/worker/pro targets, plus esbuild directly for the Node CJS/ESM outputs, orchestrated through a postbuild script. TypeScript runs in strict mode targeting ES2022 with NodeNext module resolution. Testing runs on Vitest with a dedicated coverage config, and Biome handles both linting and formatting in a single tool. CI is GitHub Actions with dedicated workflows for unit tests, cross-runtime integration tests, unsupported-environment tests, npm publishing, and a GitHub Pages deployment for a live demo and generated API docs.

Code Quality

Tests are organized under numbered unit suites (one per public method, plus edge cases for passwords, geometry, malformed PDFs, and multi-file handling) and a separate integration suite that verifies the package under real ESM, CJS, Jest, and AVA consumption scenarios plus a TypeScript compilation check — a more thorough approach than typical unit-only coverage. Vitest with v8 coverage plus Codecov tracks coverage over time. Every public class and method carries structured documentation comments that also feed a published API reference site. Error handling is explicit and typed: pdfjs-dist’s internal exceptions are translated into typed classes callers can instanceof-check, rather than surfacing raw library errors.

API Design The public surface is a single class instantiated once per document, with one method per extraction concern, each accepting a shared parameters shape for page selection so the calling convention stays consistent across methods, and each returning a typed result object with both raw data and convenience accessors. Getting started requires one import and a destroy() call to free memory. Migration friction from the older major version is addressed directly with a side-by-side code comparison and a backward-compatible method. Documentation is unusually extensive for an open-source package: multiple dedicated reference docs covering options, the CLI, worker usage, and troubleshooting, plus a wide set of runnable examples spanning CJS, ESM, HTML/CDN, worker, and large-file scenarios.

Used by 23 apps in this directory

TypeScript
96%
Other

Refly

AI Development · Automation · No Code Platforms

7,537

Build deterministic, versioned agent skills from natural language—run them anywhere from Claude Code to Slack.

View details
68
Repo Health
76
Technical
63
Dependency
Built with
TypeScript 96%
Updated 1 weeks ago
TypeScript
98%
Apache 2.0

rowboat

AI Assistants · AI Development

18,060

Build, test, and deploy multi-agent AI workflows with a visual editor, RAG data sources, MCP tool integration, and a production-ready REST API.

View details
88
Repo Health
72
Technical
65
Dependency
Built with
TypeScript 98%
Updated 1 weeks ago
TypeScript
96%
Other

superglue

AI Agents · Data Engineering · Developer Tools

2,066

superglue is an AI-agent-driven integration engine that turns plain-English descriptions of enterprise systems into production-grade API tools, ERP/CRM connectors, and data pipelines — self-hosted or cloud, Y Combinator-backed (W25).

View details
42
Repo Health
79
Technical
67
Dependency
Built with
TypeScript 96%
Updated 2 months ago
TypeScript
99%
Other

Teable

Databases · No Code Platforms

21,920

A no-code PostgreSQL database with spreadsheet UX, real-time collaboration, and native AI agents — built for teams that outgrow Airtable.

View details
78
Repo Health
76
Technical
62
Dependency
Built with
TypeScript 99%
Updated 1 weeks ago
HTML
68%
AGPL 3.0

ToolJet

AI Agents · Low Code Platforms · No Code Platforms

41,123

Open-source AI-native platform to build and deploy internal tools, workflows, and AI agents with a visual drag-and-drop builder and 80+ data source integrations.

View details
94
Repo Health
81
Technical
63
Dependency
Built with
HTML 68%
JavaScript 20%
Updated 6 days ago

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers