PHPackages                             dragomirt/pdf-to-text - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [PDF &amp; Document Generation](/categories/documents)
4. /
5. dragomirt/pdf-to-text

ActiveLibrary[PDF &amp; Document Generation](/categories/documents)

dragomirt/pdf-to-text
=====================

Extract text from a pdf

1.5.3(4y ago)03.9k1MITPHPPHP ^7.3|^8.0

Since Dec 31Pushed 4y agoCompare

[ Source](https://github.com/dragomirt/pdf-to-text)[ Packagist](https://packagist.org/packages/dragomirt/pdf-to-text)[ Docs](https://github.com/dragomirt/pdf-to-text)[ Fund](https://spatie.be/open-source/support-us)[ RSS](/packages/dragomirt-pdf-to-text/feed)WikiDiscussions master Synced 3w ago

READMEChangelog (4)Dependencies (2)Versions (14)Used By (0)

Extract text from a pdf
=======================

[](#extract-text-from-a-pdf)

Convert pdf to plain text, even on empty and encrypted files. This package is based on [spatie/pdf-to-text](https://github.com/spatie/pdf-to-text).

Requirements
------------

[](#requirements)

Behind the scenes this package leverages [pdftotext](https://en.wikipedia.org/wiki/Pdftotext). You can verify if the binary installed on your system by issueing this command:

```
which pdftotext
```

If it is installed it will return the path to the binary.

To install the binary you can use this command on Ubuntu or Debian:

```
apt-get install poppler-utils
```

On a mac you can install the binary using brew

```
brew install poppler
```

If you're on RedHat or CentOS use this:

```
yum install poppler-utils
```

To use the OCR functionality, install the following dependencies, in accordance to your package manager. The following example is based on Ubuntu.

```
apt-get install tesseract-ocr ocrmypdf
```

To use the decryption functionality, install the following dependencies, in accordance to your package manager.

```
#this is Debian based
apt-get install qpdf
```

Installation
------------

[](#installation)

You can install the package via composer:

```
composer require spatie/pdf-to-text
```

Usage
-----

[](#usage)

Extracting text from a pdf is easy.

```
$text = (new Pdf())
    ->setPdf('book.pdf')
    ->text();
```

Or easier:

```
echo Pdf::getText('book.pdf');
```

By default the package will assume that the `pdftotext` command is located at `/usr/bin/pdftotext`. If it is located elsewhere pass its binary path to constructor

```
$text = (new Pdf('/custom/path/to/pdftotext'))
    ->setPdf('book.pdf')
    ->text();
```

or as the second parameter to the `getText` static method:

```
echo Pdf::getText('book.pdf', '/custom/path/to/pdftotext');
```

Sometimes you may want to use [pdftotext options](https://linux.die.net/man/1/pdftotext). To do so you can set them up using the `setOptions` method.

```
$text = (new Pdf())
    ->setPdf('table.pdf')
    ->setOptions(['layout', 'r 96'])
    ->text()
;
```

or as the third parameter to the `getText` static method:

```
echo Pdf::getText('book.pdf', null, ['layout', 'opw myP1$$Word']);
```

Please note that successive calls to `setOptions()` will overwrite options passed in during previous calls.

If you need to make multiple calls to add options (for example if you need to pass in default options when creating the `Pdf` object from a container, and then add context-specific options elsewhere), you can use the `addOptions()` method:

```
$text = (new Pdf())
    ->setPdf('table.pdf')
    ->setOptions(['layout', 'r 96'])
    ->addOptions(['f 1'])
    ->text()
;
```

To extract data from empty files, use the `scan` method, with it's respective options setter. The method `decrypt` opens "encrypted" files with empty passwords.

```
$text = (new Pdf())
    ->setPdf('table.pdf')
    ->setOptions(['layout', 'r 96'])
    ->addOptions(['f 1'])
    ->setScanOptions(['-l nld+eng', '--skip-text'])
    ->scan()
    ->decrypt()
    ->text()
;
```

Testing
-------

[](#testing)

```
 composer test
```

Credits
-------

[](#credits)

- [Freek Van der Herten](https://github.com/freekmurze)
- [Dragomir Țurcanu](https://github.com/dragomirt)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

35

—

LowBetter than 77% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity17

Limited adoption so far

Community15

Small or concentrated contributor base

Maturity75

Established project with proven stability

 Bus Factor1

Top contributor holds 57.6% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~180 days

Recently: every ~92 days

Total

13

Last Release

1667d ago

Major Versions

0.0.1 → 1.0.02015-12-31

PHP version history (3 changes)0.0.1PHP ^7.0

1.3.0PHP ^7.3

1.4.0PHP ^7.3|^8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/29e1f269bc8c004e4cc1b695d380bdf8b761b92a5ab347bb705fd2553987c97c?d=identicon)[dragomirt](/maintainers/dragomirt)

---

Top Contributors

[![freekmurze](https://avatars.githubusercontent.com/u/483853?v=4)](https://github.com/freekmurze "freekmurze (53 commits)")[![nyamsprod](https://avatars.githubusercontent.com/u/51073?v=4)](https://github.com/nyamsprod "nyamsprod (16 commits)")[![dragomirt](https://avatars.githubusercontent.com/u/22262264?v=4)](https://github.com/dragomirt "dragomirt (10 commits)")[![sebastiandedeyne](https://avatars.githubusercontent.com/u/1561079?v=4)](https://github.com/sebastiandedeyne "sebastiandedeyne (4 commits)")[![AdrianMrn](https://avatars.githubusercontent.com/u/12762044?v=4)](https://github.com/AdrianMrn "AdrianMrn (3 commits)")[![RayDabbah](https://avatars.githubusercontent.com/u/25418202?v=4)](https://github.com/RayDabbah "RayDabbah (2 commits)")[![JayBizzle](https://avatars.githubusercontent.com/u/340752?v=4)](https://github.com/JayBizzle "JayBizzle (1 commits)")[![peter279k](https://avatars.githubusercontent.com/u/9021747?v=4)](https://github.com/peter279k "peter279k (1 commits)")[![carusogabriel](https://avatars.githubusercontent.com/u/16328050?v=4)](https://github.com/carusogabriel "carusogabriel (1 commits)")[![srmklive](https://avatars.githubusercontent.com/u/839335?v=4)](https://github.com/srmklive "srmklive (1 commits)")

---

Tags

spatiepdfOCRpdf-to-textdragomirt

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/dragomirt-pdf-to-text/health.svg)

```
[![Health](https://phpackages.com/badges/dragomirt-pdf-to-text/health.svg)](https://phpackages.com/packages/dragomirt-pdf-to-text)
```

###  Alternatives

[spatie/browsershot

Convert a webpage to an image or pdf using headless Chrome

5.2k35.1M142](/packages/spatie-browsershot)[knplabs/knp-snappy

PHP library allowing thumbnail, snapshot or PDF generation from a url or a html page. Wrapper for wkhtmltopdf/wkhtmltoimage.

4.5k71.0M59](/packages/knplabs-knp-snappy)[spatie/pdf-to-text

Extract text from a pdf

1.0k7.3M50](/packages/spatie-pdf-to-text)[spatie/pdf-to-image

Convert a pdf to an image

1.4k16.1M91](/packages/spatie-pdf-to-image)[pontedilana/php-weasyprint

PHP library allowing PDF generation from an url or a html page. Wrapper for Kozea/WeasyPrint.

781.2M14](/packages/pontedilana-php-weasyprint)[vaites/php-apache-tika

Apache Tika bindings for PHP: extracts text from documents and images (with OCR), metadata and more...

1171.5M2](/packages/vaites-php-apache-tika)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
