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 🙏

© 2024 – Pkg Stats / Ryan Hefner

office-text-extractor-browser

v3.1.4

Published

Fork of office-text-extractor with unreleased changes that include browser support

Downloads

15

Readme

office-text-extractor

yet another library to extract text from docx, pptx, xlsx, and pdf files.

similar libraries

there are other great libraries that do the same job and have inspired this project, such as:

however, office-text-extractor has the following differences:

  • parses file based on its mime type, not its file extension.
  • does not spawn a child process to use a tool installed on the device.
  • reads and returns text from the file if it contains plain text.

libraries used

this package uses some amazing existing libraries that perform better than the ones that originally existed in this module, and are therefore used instead:

a big thank you to the contributors of these projects!

installation

node

from version 2.0.0 onwards, this package is pure esm. please read this article for a guide on how to ensure your project can import this library.

to use office-text-extractor in an Node project, install it using npm/pnpm/yarn:

> npm install office-text-extractor
> pnpm add office-text-extractor
> yarn add office-text-extractor

~browser~

the library currently cannot be used in the browser due to its usage of the node:buffer library. pull requests that can replace node:buffer with a different library are welcome!

usage

an example of using the library to extract text is as follows:

import { readFile } from 'node:fs/promises'
import { getTextExtractor } from 'office-text-extractor'

// this function returns a new instance of the `TextExtractor` class, with the default
// extraction methods (docx, pptx, xlsx, pdf) registered.
const extractor = getTextExtractor()

// extract text from a url, because that's a neat first example :p
const url = 'https://raw.githubusercontent.com/gamemaker1/office-text-extractor/rewrite/test/fixtures/docs/pptx.pptx'
const text = await extractor.extractText({ input: url, type: 'url' })

// you can extract text from a file too, like so:
const path = 'stuff/boring.pdf'
const text = await extractor.extractText({ input: path, type: 'file' })

// if you have a buffer with the file in it, you can pass that too:
const buffer = await readFile(path)
const text = await extractor.extractText({ input: buffer, type: 'buffer' })

console.log(text)

the following is an example of how to create and use your own text extraction method:

import { type Buffer } from 'node:buffer'
import { TextExtractor, type TextExtractionMethod } from 'office-text-extractor'

/**
 * Extracts text from images.
 */
class ImageExtractor implements TextExtractionMethod {
  /**
   * The mime types of the file that the extractor accepts.
   */
  mimes = ['image/png', 'image/jpeg']

  /**
   * Extracts text from the image file passed by the user.
   */
  apply = async (input: Buffer): Promise<string> {
    const text = await processImage(input)
    return text
  }
}

// create a new extractor and register our extraction method
const extractor = new TextExtractor()
extractor.addMethod(new ImageExtractor())

// then use it like you would normally
const text = await extractor.extractText({ input: '...', type: '...' }
console.log(text)

license

this project is licensed under the ISC license. please see license.md for more details.