# pdf-text-extract

> Extract text from pdfs that contain searchable pdf text

Latest version **1.5.0** (published 2017-03-24) · BSD license · 0 weekly downloads

## Install

```sh
npm install pdf-text-extract
pnpm add pdf-text-extract
yarn add pdf-text-extract
bun add pdf-text-extract
```

Provides the command `pdf-text-extract`.

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.5.0 |
| Published | 2017-03-24 |
| First published | 2013-03-20 |
| Weekly downloads | 0 |
| License | BSD |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Noah Isaacson |
| Maintainers | clewfirst, nisaacson |
| Keywords | pdf, extract, pdftotext, text, extract |

## Links

- npm: https://www.npmjs.com/package/pdf-text-extract
- Repository: https://github.com/nisaacson/pdf-text-extract
- Homepage: https://github.com/nisaacson/pdf-text-extract#readme
- Issues: https://github.com/nisaacson/pdf-text-extract/issues
- npm.io page: https://npm.io/package/pdf-text-extract

## Dependencies (1)

- [yargs](https://npm.io/package/yargs.md) ^1.2.5

## Alternatives

- [@cantoo/pdf-lib](https://npm.io/package/@cantoo/pdf-lib.md) — 297.9K weekly downloads
- [datatables.net-buttons](https://npm.io/package/datatables.net-buttons.md) — 200.1K weekly downloads
- [@ckeditor/ckeditor5-export-pdf](https://npm.io/package/@ckeditor/ckeditor5-export-pdf.md) — 167.0K weekly downloads
- [scanbot-web-sdk](https://npm.io/package/scanbot-web-sdk.md) — 15.0K weekly downloads
- [@syncfusion/ej2-angular-pdfviewer](https://npm.io/package/@syncfusion/ej2-angular-pdfviewer.md) — 8.8K weekly downloads

## Recent versions

- 1.5.0 (latest) — 2017-03-24
- 1.4.1 — 2015-10-28
- 1.4.0 — 2015-10-26
- 1.3.1 — 2015-09-27
- 1.3.0 — 2015-09-27
- 1.2.0 — 2015-07-28
- 1.1.4 — 2014-08-11
- 1.1.3 — 2014-07-25
- 1.1.2 — 2014-06-22
- 1.1.1 — 2014-06-22
- 1.1.0 — 2014-02-27
- 1.0.13 — 2014-02-27
- 1.0.12 — 2014-02-27
- 1.0.11 — 2013-06-13
- 1.0.10 — 2013-06-13
- … 8 more at https://npm.io/package/pdf-text-extract/versions

## README

# PDF Text Extract

Extract text from pdfs that contain searchable pdf text. The module is wrapper that calls the `pdftotext` command to perform the actual extraction

[![Build Status](https://travis-ci.org/nisaacson/pdf-text-extract.png?branch=master)](https://travis-ci.org/nisaacson/pdf-text-extract) [![Dependency Status](https://david-dm.org/nisaacson/pdf-text-extract.png)](https://david-dm.org/nisaacson/pdf-text-extract)

# Installation
```bash
npm install --save pdf-text-extract
```


You will need the `pdftotext` binary available on your path. There are packages available for many different operating systems

See [https://github.com/nisaacson/pdf-extract#osx](https://github.com/nisaacson/pdf-extract#osx) for how to install the `pdftotext` command


# Usage

## As a module

`extract(filePath, [options], [pdftotextcommand], callback)`

Options and pdftotextcommand are not required.


```javascript
var path = require('path')
var filePath = path.join(__dirname, 'test/data/multipage.pdf')
var extract = require('pdf-text-extract')
extract(filePath, function (err, pages) {
  if (err) {
    console.dir(err)
    return
  }
  console.dir(pages)
})
```
The output will be an array of where each entry is a page of text. If you want just a string of all pages you can set the option to `splitPages: false`.

```javascript
var filePath = path.join(__dirname, 'test/data/multipage.pdf')
var extract = require('pdf-text-extract')
extract(filePath, { splitPages: false }, function (err, text) {
  if (err) {
    console.dir(err)
    return
  }
  console.dir(text)
})
```

You can set the following options:
- `firstPage`: First page to extract
- `lastPage`: Last page to extract
- `resolution`: in dpi, as is specified by pdftotext -r
- `crop`: Should be an object { x:x, y:y, w:w, h:h }
- `layout`: Should be either `layout`, `raw` or `htmlmeta`. Default: `layout`
- `encoding`: Should be either `UCS-2`, `ASCII7`, `Latin1`, `UTF-8`, `ZapfDingbats` or `Symbol`. Default: `UTF-8`
- `eol`: End of line convention. One of either: `unix`, `dos` or `mac`
- `ownerPassword`: Owner password (for encrypted files)
- `userPassword`: User password (for encrypted files)
- `splitPages`: If true, the result will be and array of pages. Default: true.


If needed you can pass an optional arguments to the extract function. These will be passed to the `child_process.spawn` call.

```javascript
var filePath = path.join(__dirname, 'test/data/multipage.pdf')
var extract = require('pdf-text-extract')
var options = {
  cwd: "./"
}
extract(filePath, options, function (err, pages) {
  if (err) {
    console.dir(err)
    return
  }
  console.dir('extracted pages', pages)
})
```

You can also override the command for `pdftotext` if it is installed in a location that is not available in the `PATH` environment variable


```javascript
var filePath = path.join(__dirname, 'test/data/multipage.pdf')
var pdfToTextCommand = '/opt/bin/pdftotext'
var extract = require('pdf-text-extract')
var options = {
  cwd: "./"
}
extract(filePath, options, pdfToTextCommand, function (err, pages) {
  if (err) {
    console.dir(err)
    return
  }
  console.dir('extracted pages', pages)
})
```

## As a command line tool

```bash
npm install -g pdf-text-extract
```

Execute with the filePath as an argument. Output will be json-formatted array of pages

```bash
pdf-text-extract ./test/data/multipage.pdf
# outputs
# ['<page 1 content...>', '<page 2 content...>']
```

# Test

```bash
# install dev dependencies
npm install
# run tests
npm test

---
_Source: https://npm.io/package/pdf-text-extract · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
