Find Similar Packages for pdf-parse
pdf-parseSimilar Packages:
Npm Package Weekly Downloads Trend
3 Years
🌟 Show real-time usage chart on pdf-parse's README.md, just copy the code below.
## Usage Trend
[![Usage Trend of pdf-parse](https://npm-compare.com/img/npm-trend/THREE_YEARS/pdf-parse.png)](https://npm-compare.com/pdf-parse#timeRange=THREE_YEARS)
Cumulative GitHub Star Trend
Stat Detail
Package
Downloads
Stars
Size
Issues
Publish
License
pdf-parse1,358,175
338 MB311 hours agoApache-2.0
README for pdf-parse

pdf-parse

A pure TypeScript/JavaScript, cross-platform module for extracting text, images, and tabular data from PDF files.

npm downloads npm version node version tests biome vitest codecov socket badge test & coverage reports


Contributing Note: When opening an issue, please attach the relevant PDF file if possible. Providing the file will help us reproduce and resolve your issue more efficiently. For detailed guidelines on how to contribute, report bugs, or submit pull requests, see: contributing to pdf-parse

Features

  • Supports Node.js and browsers
  • CommonJS and ESM support
  • Vulnerability and security info : security policy
  • Extract page text : getText
  • Extract embedded images : getImage
  • Render pages as images : pageToImage
  • Detect and extract tabular data : getTable
  • For additional usage examples, check the test folder and live demo
  • Live demo source: gh-pages branch

Similar Packages

Benchmark Note: The benchmark currently runs only against pdf2json. I don't know the current state of pdf2json — the original reason for creating pdf-parse was to work around stability issues with pdf2json. I deliberately did not include pdf-parse or other pdf.js-based packages in the benchmark because dependencies conflict. If you have recommendations for additional packages to include, please open an issue.benchmark results

Installation

npm install pdf-parse
# or
pnpm add pdf-parse
# or
yarn add pdf-parse
# or
bun add pdf-parse

Basic Usage

  • High-level helper for v1 compatibility: pdf
  • Full API: PDFParse

CommonJS Example, helper for v1 compatibility

const pdf  = require('pdf-parse');
// or 
// const {pdf,PDFParse}  = require('pdf-parse');
const fs = require('fs');

const data = fs.readFileSync('test.pdf');

pdf(data).then(result=>{
    console.log(result.text);
});

getText — Extract Text

// Node / ESM
import { PDFParse } from 'pdf-parse';
import { readFile } from 'node:fs/promises';

const buffer = await readFile('test/test-01/test.pdf');

const parser = new PDFParse({ data: buffer });
const textResult = await parser.getText();
console.log(textResult.text);

For a complete list of configuration options, see:

Usage Examples

pageToImage — Render Page to PNG

// Node / ESM
import { PDFParse } from 'pdf-parse';
import { readFile, writeFile } from 'node:fs/promises';

const buffer = await readFile('test/test-01/test.pdf');

const parser = new PDFParse({ data: buffer });
const result = await parser.pageToImage();

for (const pageData of result.pages) {
    const imgFileName = `page_${pageData.pageNumber}.png`;
    await writeFile(imgFileName, pageData.data, { flag: 'w' });
}

getImage — Extract Embedded Images

// Node / ESM
import { PDFParse } from 'pdf-parse';
import { readFile, writeFile } from 'node:fs/promises';

const buffer = await readFile('test/test-01/test.pdf');

const parser = new PDFParse({ data: buffer });
const result = await parser.getImage();

for (const pageData of result.pages) {
    for (const pageImage of pageData.images) {
        const imgFileName = `page_${pageData.pageNumber}-${pageImage.fileName}.png`;
        await writeFile(imgFileName, pageImage.data, { flag: 'w' });
    }
}

getTable — Extract Tabular Data

// Node / ESM
import { PDFParse } from 'pdf-parse';
import { readFile } from 'node:fs/promises';

const buffer = await readFile('test/test-01/test.pdf');

const parser = new PDFParse({ data: buffer });
const result = await parser.getTable();

for (const pageData of result.pages) {
    for (const table of pageData.tables) {
        console.log(table);
    }
}

Web / Browser

  • After running npm run build, you will find both regular and minified browser bundles in dist/browser (e.g., pdf-parse.es.js and pdf-parse.es.min.js).
  • Check: live demo
  • Live demo source: gh-pages branch

Use the minified versions (.min.js) for production to reduce file size, or the regular versions for development and debugging.

You can use any of the following browser bundles depending on your module system and requirements:

  • pdf-parse.es.js or pdf-parse.es.min.js for ES modules
  • pdf-parse.umd.js or pdf-parse.umd.min.js for UMD/global usage

You can include the browser bundle directly from a CDN. Use the latest version:

Or specify a particular version:

Worker Note: In browser environments, the package sets pdfjs.GlobalWorkerOptions.workerSrc automatically when imported from the built browser bundle. If you use a custom build or host pdf.worker yourself, configure pdfjs accordingly.