npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

pdf-extract-text

v0.1.3

Published

A fast, native Node.js module to extract and process text from PDF files using Rust and N-API. Built with [Tokio](https://tokio.rs/), [`pdf-extract`](https://docs.rs/pdf-extract), and [`text-splitter`](https://crates.io/crates/text-splitter), this package

Readme

PDF Text Extractor

A fast, native Node.js module to extract and process text from PDF files using Rust and N-API. Built with Tokio, pdf-extract, and text-splitter, this package provides efficient and easy-to-use async APIs.

Features

  • High-performance native code (Rust)
  • Asynchronous functions (non-blocking I/O)
  • Useful for LLM pipelines and search indexing
  • Extract cleaned text from PDF files
  • Split PDF text into pages with automatic page number detection
  • Generate overlapping text chunks with configurable sizes
  • TypeScript support

Installation

npm install pdf-extract-text
# or
yarn add pdf-extract-text

Usage

Basic Text Extraction

JavaScript

const { extractTextFromPdf } = require('pdf-extract-text');

async function main() {
  try {
    const text = await extractTextFromPdf('./document.pdf');
    console.log('Cleaned PDF text:', text);
  } catch (error) {
    console.error('Error:', error.message);
  }
}

main();

TypeScript

import { extractTextFromPdf } from 'pdf-extract-text';

async function main() {
  try {
    const text: string = await extractTextFromPdf('./document.pdf');
    console.log('Cleaned PDF text:', text);
  } catch (error) {
    console.error('Error:', (error as Error).message);
  }
}

main();

Page-based Extraction

JavaScript

const { extractTextPages } = require('pdf-extract-text');

async function extractPages() {
  try {
    const pages = await extractTextPages('./document.pdf');
    pages.forEach(page => {
      console.log(`Page ${page.page}:`);
      console.log(page.text);
      console.log('\n---\n');
    });
  } catch (error) {
    console.error('Error:', error.message);
  }
}

extractPages();

TypeScript

import { extractTextPages, Page } from 'pdf-extract-text';

async function extractPages() {
  try {
    const pages: Page[] = await extractTextPages('./document.pdf');
    pages.forEach((page: Page) => {
      console.log(`Page ${page.page}:`);
      console.log(page.text);
      console.log('\n---\n');
    });
  } catch (error) {
    console.error('Error:', (error as Error).message);
  }
}

extractPages();

Text Chunking with Overlaps

JavaScript

const { extractTextChunks } = require('pdf-extract-text');

async function chunkText() {
  try {
    const chunks = await extractTextChunks('./document.pdf', 1000, 200);
    chunks.forEach(chunk => {
      console.log(`Chunk ${chunk.id}:`);
      console.log(chunk.text);
      console.log('\n=====\n');
    });
  } catch (error) {
    console.error('Error:', error.message);
  }
}

chunkText();

TypeScript

import { extractTextChunks, TextChunk } from 'pdf-extract-text';

async function chunkText() {
  try {
    const chunks: TextChunk[] = await extractTextChunks('./document.pdf', 1000, 200);
    chunks.forEach((chunk: TextChunk) => {
      console.log(`Chunk ${chunk.id}:`);
      console.log(chunk.text);
      console.log('\n=====\n');
    });
  } catch (error) {
    console.error('Error:', (error as Error).message);
  }
}

chunkText();

Types

type Page = {
  page: number;
  text: string;
};

type TextChunk = {
  id: number;
  text: string;
};

API Documentation

extractTextFromPdf(path: string): Promise<string>

Extracts and cleans text from a PDF file

  • path: Path to PDF file
  • Returns: Cleaned text with numeric-only lines removed

extractTextPages(path: string): Promise<Page[]>

Extracts text split into pages

interface Page {
  page: number;
  text: string;
}

extractTextChunks(path: string, chunkSize: number, chunkOverlap: number): Promise<TextChunk[]>

Generates overlapping text chunks

interface TextChunk {
  id: number;
  text: string;
}
  • chunkSize: Target chunk size in characters
  • chunkOverlap: Overlap between chunks (must be < chunkSize)

Error Handling

All functions throw errors with descriptive messages for:

  • File not found or read errors
  • PDF parsing failures
  • Invalid chunk configurations (overlap >= chunk size)

Use Cases

  • Document understanding and chunking for LLMs
  • PDF content extraction for chatbots or search
  • Indexing and pre-processing for embeddings

Processing Details

  1. Text Cleaning:

    • Removes lines containing only numeric characters
    • Preserves original line breaks and formatting
  2. Page Detection:

    • Splits text at lines containing only page numbers
    • Handles variable page number positions
  3. Chunking:

    • Uses semantic-aware splitting (paragraphs/sentences)
    • Maintains context with overlapping chunks
    • Configurable through simple parameters

Requirements

  • Node.js 16+
  • Rust (for building from source)

License

MIT