Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
@mtamayo/office-text-extractor
Advanced tools
Yet another library to extract text from MS Office and PDF files
yet another library to extract text from docx, pptx, xlsx, and pdf files.
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:
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!
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
to use this package in the browser, fetch it using your preferred cdn:
<script src="https://unpkg.com/office-text-extractor@latest/build/index.js"></script>
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)
this project is licensed under the ISC license. please see license.md
for more details.
FAQs
Yet another library to extract text from MS Office and PDF files
The npm package @mtamayo/office-text-extractor receives a total of 0 weekly downloads. As such, @mtamayo/office-text-extractor popularity was classified as not popular.
We found that @mtamayo/office-text-extractor demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.