Extraction · Node.js and TypeScript

Extract text from a PDF in Node.js

Pull the text out of any PDF from Node.js. rust-pdf walks the content stream, maps shown glyph codes back to Unicode through each font's ToUnicode map, and infers spaces and line breaks, including two-byte Type0 fonts and CJK.

Last updated: 2026-06-29

Why Node.js and TypeScript needs this

Pulling text out of a PDF in Node is usually delegated to a spawned CLI like pdftotext, which means temp files, process overhead and brittle parsing of its output.

Reliable extraction is harder than it looks: codes in the stream are font-specific and must be mapped to Unicode, and spacing has to be inferred from positioning. rust-pdf does both, so the text you get back is the text a human reads, ready for search, indexing or data pipelines.

extractText takes the PDF as a Node Buffer and returns a plain string, so you read with fs.promises.readFile, await the call in a pipeline, and push the text to a search index or queue. extractImagesToDir writes rasters to a folder and returns the count; both run in-process through the Koffi binding with no node-gyp and no spawned CLI.

  • Maps glyph codes to Unicode via each font's ToUnicode map, including two-byte Type0 and CJK.
  • Infers spaces from large negative adjustments and line breaks from text positioning.
  • Pull raster images out too: JPEGs verbatim as .jpg, everything else as .png.

Extract text in Node.js with rust-pdf

Install from npm, read the file into a Buffer, and call extractText. The snippet below is real Node.js from the reference docs.

npm install rustpdf

Node.js
const data = fs.readFileSync("report.pdf");
console.log(rustpdf.extractText(data));

const n = rustpdf.extractImagesToDir(data, "out_images/");   // returns how many were written
console.log(`wrote ${n} image(s)`);
Validated by: pdftotext

Text and image extraction are part of the free tier in Node.js, no license token needed.

The full Node.js extraction reference is in the documentation.

Text extraction in Node.js: FAQ

Does it extract Unicode and CJK text in Node.js?

Yes. Each shown code is mapped back to Unicode through the font's ToUnicode CMap, including two-byte Type0 fonts, so Japanese, Greek, Arabic and other scripts come back correctly.

Can it extract scanned PDFs?

No. Extraction reads the text layer of a PDF. A scanned document is an image with no text layer, which needs OCR first. For PDFs that contain real text, extraction is exact.

Is text extraction free?

Yes. Text and image extraction are part of the free tier in Node.js. No license token is required.

Is extractText synchronous, and how do I run it without blocking?

extractText runs in process and returns the string directly, so for large batches in an Express or serverless handler you await it inside an async job or hand it to a worker thread. There is no child process to manage, since the Koffi binding calls the native core directly.

Turn PDFs into searchable text in your pipeline

One Rust core, the same Unicode extraction in every language. Extraction is free; license the corporate features only when you ship them.