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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@cedrugs/pdf-parse

v1.0.0

Published

Fork of pdf-parse with fixes

Readme

@cedrugs/pdf-parse

Pure JavaScript, cross-platform PDF text & metadata extraction.
A maintained fork of pdf-parse with bundled TypeScript types, ESM-friendly default export, and Node 18+ support.

npm license node


Why this fork?

  • Types included — ships index.d.ts (no need for @types/pdf-parse).
  • ESM & CJS friendly — default import works out of the box.
  • Same API as upstream for drop-in replacement.
  • Node 18+ minimum for modern runtimes.

If you want to keep your existing import pdf from "pdf-parse" usage, see the Install (alias) section.


Installation

Option A — Use this scoped package directly

npm i @cedrugs/pdf-parse
# or
pnpm add @cedrugs/pdf-parse
# or
yarn add @cedrugs/pdf-parse

Option B — Keep the old import name via npm alias

npm i pdf-parse@npm:@cedrugs/pdf-parse

Now import pdf from "pdf-parse" continues to work, but resolves to this fork.


Basic Usage — Local Files

CommonJS

const fs = require('fs');
const pdf = require('@cedrugs/pdf-parse'); // or 'pdf-parse' if using the alias

const dataBuffer = fs.readFileSync('path/to/file.pdf');

pdf(dataBuffer).then((data) => {
    // number of pages
    console.log(data.numpages);
    // number of rendered pages
    console.log(data.numrender);
    // PDF info
    console.log(data.info);
    // PDF metadata
    console.log(data.metadata);
    // PDF.js version
    // see https://mozilla.github.io/pdf.js/getting_started/
    console.log(data.version);
    // PDF text
    console.log(data.text);
});

ESM / TypeScript

import pdf from '@cedrugs/pdf-parse'; // default export supported
import { readFileSync } from 'node:fs';

const buf = readFileSync('path/to/file.pdf');
const data = await pdf(buf);

console.log(data.text);

Basic Usage — HTTP

You can use packages like crawler-request which integrate with pdf-parse.


Exception Handling

const fs = require('fs');
const pdf = require('@cedrugs/pdf-parse');

const buf = fs.readFileSync('path/to/file.pdf');

pdf(buf)
    .then((data) => {
        // use data
    })
    .catch((err) => {
        // handle exceptions
        console.error(err);
    });

TypeScript

This fork bundles its own .d.ts. No external @types/pdf-parse needed.

import pdf from '@cedrugs/pdf-parse';

const res = await pdf(Buffer.from('...'));
res.text;       // string
res.numpages;   // number
res.version;    // "default" | "v1.9.426" | "v1.10.100" | "v1.10.88" | "v2.0.550"

Options

const DEFAULT_OPTIONS = {
    // internal page parser callback
    // set this if you need a custom output format instead of raw text
    pagerender: render_page,

    // max page number to parse (<= 0 means “all pages”)
    max: 0,

    // see https://mozilla.github.io/pdf.js/getting_started/
    version: 'v1.10.100'
};

pagerender (callback)

Customize how each page is rendered/extracted if you need structured output beyond plain text.

max (number)

Maximum number of pages to parse. Use 0 or a negative value to parse all pages.

version (string, pdf.js version)

  • 'default'
  • 'v1.9.426'
  • 'v1.10.100'
  • 'v1.10.88'
  • 'v2.0.550'

Default version is v1.10.100. See the pdf.js getting started guide.


Extend — Custom pagerender

function render_page(pageData) {
    // see https://mozilla.github.io/pdf.js/
    const render_options = {
        // replace all whitespace with standard spaces (0x20)
        normalizeWhitespace: false,
        // do not attempt to combine cedrugse-line TextItems
        disableCombineTextItems: false
    };

    return pageData.getTextContent(render_options).then((textContent) => {
        let lastY;
        let text = '';
        for (const item of textContent.items) {
            if (lastY === item.transform[5] || !lastY) {
                text += item.str;
            } else {
                text += '\n' + item.str;
            }
            lastY = item.transform[5];
        }
        return text;
    });
}

const options = { pagerender: render_page };
const dataBuffer = require('fs').readFileSync('path/to/file.pdf');

require('@cedrugs/pdf-parse')(dataBuffer, options).then((data) => {
    // use custom-formatted output
});

Similar Packages

(Different trade-offs: dependencies, maintenance, platform support, and output formats.)


Tests

  • npm test (runs mocha)
  • See the test directory in upstream for usage ideas; contributions adding tests here are welcome.

Support / Issues


License

MIT

Acknowledgements

This project builds on the excellent work of the original pdf-parse and the PDF.js team.