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

react-native-pdf-text-extractor

v0.1.1

Published

Fully offline, on-device PDF text extraction for React Native (iOS PDFKit, Android PdfBox-Android)

Downloads

147

Readme

react-native-pdf-text-extractor

Fully offline, on-device PDF text extraction for React Native. No network calls, no cloud OCR — text is extracted locally using each platform's native PDF stack:

This library extracts text embedded in a PDF (e.g. text layers, generated documents). It does not perform OCR — scanned/image-only pages will resolve to an empty string rather than throwing.

Installation

npm install react-native-pdf-text-extractor

iOS

cd ios && pod install

Requires iOS 15.1+.

Android

No extra setup — com.tom-roush:pdfbox-android resolves automatically from Maven Central. Minimum SDK 24.

Usage

import {
  getPageCount,
  extractText,
  extractAllText,
  extractPageText,
} from 'react-native-pdf-text-extractor';

const pageCount = await getPageCount(filePath);
// 12

const wholeDocument = await extractText(filePath);
// "Page 1 text\nPage 2 text\n..."

const perPage = await extractAllText(filePath);
// ["Page 1 text", "Page 2 text", ...]

const secondPage = await extractPageText(filePath, 1); // 0-indexed
// "Page 2 text"

API

getPageCount(filePath: string): Promise<number>

Resolves with the number of pages in the PDF.

extractText(filePath: string, options?: ExtractOptions): Promise<string>

Extracts the text of every page and concatenates it into a single string, separated by newlines.

Pass { normalize: true } to clean up common extraction artifacts (see Text normalization) before the promise resolves. Omitting options leaves the text exactly as extracted, unchanged from previous versions.

await extractText(filePath, { normalize: true });
// runs every normalization step with its default settings

await extractText(filePath, { normalize: { dehyphenate: false } });
// runs normalization, but leaves hyphenated line-wraps alone

extractAllText(filePath: string, options?: ExtractOptions): Promise<string[]>

Extracts the text of every page, returned as one string per page (index 0 is the first page). A page with no extractable text (e.g. a scanned image with no OCR layer) resolves to '' rather than throwing.

The normalize option (see Text normalization) applies to each page independently, not to the array as a whole:

await extractAllText(filePath, { normalize: true });

await extractAllText(filePath, {
  normalize: { stripInvisibleChars: true, unwrapLines: false },
});

extractPageText(filePath: string, pageIndex: number, options?: ExtractOptions): Promise<string>

Extracts the text of a single page. pageIndex is 0-indexed.

await extractPageText(filePath, 1, { normalize: true });

Text normalization

PDF text layers often carry artifacts that are harmless to read but noisy for downstream NLP — words split by a hyphen at a line-wrap, hard line breaks in the middle of a sentence, invisible control/format characters. The normalize option on extractText, extractAllText, and extractPageText (and the standalone normalizeExtractedText function) cleans these up. This is opt-in — omitting options (or passing normalize: false) leaves extracted text exactly as returned by the native extractor.

import { normalizeExtractedText } from 'react-native-pdf-text-extractor';

normalizeExtractedText('under-\nstand this'); // "understand this"

normalize accepts either true (run every step below with its default) or a partial NormalizeTextOptions object (unspecified steps still default to true):

| Option | Default | Effect | | --------------------- | ------- | --------------------------------------------------------------------------------------------------------- | | stripInvisibleChars | true | Removes invisible control/format characters (zero-width spaces, etc.), keeping \n and \t. | | dehyphenate | true | Rejoins a word split by a hyphen at a line-wrap, e.g. "under-\nstand" -> "understand". | | collapseBlankLines | true | Collapses runs of 3+ newlines down to a single blank line. | | unwrapLines | true | Replaces a single mid-paragraph line break with a space, while preserving real paragraph breaks (\n\n). |

Whitespace is always tidied (runs of spaces/tabs collapsed, trailing spaces before a newline stripped) and the result is always .trim()ed, regardless of which steps above are enabled.

filePath

All methods take a local file system path — either a bare absolute path (/data/.../document.pdf) or a file:// URL. Remote URLs and content:// URIs (as returned directly by some Android document pickers) are not supported; copy the file to a local path first (e.g. with react-native-document-picker's copyTo: 'cachesDirectory' option, or react-native-fs).

Errors

Rejections carry one of the following codes:

| Code | Meaning | | ------------------- | ----------------------------------------------------------------- | | E_FILE_NOT_FOUND | No file exists at the given path. | | E_UNSUPPORTED_URI | A content:// URI was passed instead of a local file path. | | E_INVALID_PAGE | pageIndex is out of range for the document. | | E_PDF_PROCESSING | The file could not be parsed as a PDF (corrupt, encrypted, etc.). |

filePath and pageIndex are also validated synchronously in JS before any native call is made — passing a non-string path or a non-integer/negative page index throws immediately rather than rejecting a promise.

Example app

See example/ for a runnable app that picks a PDF (or falls back to bundled sample PDFs) and displays extracted text.

Demo

🎥 Watch Demo

License

MIT