PHPackages                             casonwebdev/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. casonwebdev/pdf-to-text

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

casonwebdev/pdf-to-text
=======================

Extract text from a pdf

1.2.0(6y ago)013MITPHPPHP ^7.0CI failing

Since Apr 4Pushed 6y ago1 watchersCompare

[ Source](https://github.com/CasonWebDev/pdf-to-text)[ Packagist](https://packagist.org/packages/casonwebdev/pdf-to-text)[ Docs](https://github.com/spatie/pdf-to-text)[ RSS](/packages/casonwebdev-pdf-to-text/feed)WikiDiscussions master Synced 1w ago

READMEChangelog (1)Dependencies (2)Versions (2)Used By (0)

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

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

[![Latest Version on Packagist](https://camo.githubusercontent.com/99a626f2452c0aaff605e496890d8d0b8fd56bcb13a39dc86333193d5d758fa0/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f7370617469652f7064662d746f2d746578742e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/spatie/pdf-to-text)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)[![Build Status](https://camo.githubusercontent.com/d44a5e55f16ff3aa070729c50b3352ed7ea0afd2bb13ef0e4c36476368715a51/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f7370617469652f7064662d746f2d746578742f6d61737465722e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/spatie/pdf-to-text)[![Quality Score](https://camo.githubusercontent.com/a64fc37b6a268cf565afb5d048859a8018a897a582f3c832cd92d801a6895ec3/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f7370617469652f7064662d746f2d746578742e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/spatie/pdf-to-text)[![Total Downloads](https://camo.githubusercontent.com/606fb0e5d3ffda6e365fe92f6d61e323bebfe1a852727172c54554dd511f36be/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f7370617469652f7064662d746f2d746578742e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/spatie/pdf-to-text)

This package provides a class to extract text from a pdf.

```
use Spatie\PdfToText\Pdf;

echo Pdf::getText('book.pdf'); //returns the text from the pdf
```

Spatie is a webdesign agency based in Antwerp, Belgium. You'll find an overview of all our open source projects [on our website](https://spatie.be/opensource).

Postcardware
------------

[](#postcardware)

You're free to use this package (it's [MIT-licensed](LICENSE.md)), but if it makes it to your production environment you are required to send us a postcard from your hometown, mentioning which of our package(s) you are using.

Our address is: Spatie, Samberstraat 69D, 2060 Antwerp, Belgium.

The best postcards will get published on the open source page on our website.

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
```

If you're on RedHat or CentOS use this:

```
yum install poppler-utils
```

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()
;
```

Change log
----------

[](#change-log)

Please see [CHANGELOG](CHANGELOG.md) for more information about what has changed recently.

Testing
-------

[](#testing)

```
 composer test
```

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

Security
--------

[](#security)

If you discover any security related issues, please email  instead of using the issue tracker.

Credits
-------

[](#credits)

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

About Spatie
------------

[](#about-spatie)

Spatie is a webdesign agency based in Antwerp, Belgium. You'll find an overview of all our open source projects [on our website](https://spatie.be/opensource).

License
-------

[](#license)

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

###  Health Score

23

—

LowBetter than 27% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity5

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity51

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% 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

Unknown

Total

1

Last Release

2236d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/16c833cb35b7932f0f3db9e90ba3e92c40a7aad8be264f982f97565f9109f87e?d=identicon)[CasonWebDev](/maintainers/CasonWebDev)

---

Top Contributors

[![CasonWebDev](https://avatars.githubusercontent.com/u/6971584?v=4)](https://github.com/CasonWebDev "CasonWebDev (3 commits)")

---

Tags

spatiepdf-to-textCasonWebDev

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[spatie/pdf-to-text

Extract text from a pdf

1.0k6.7M40](/packages/spatie-pdf-to-text)[spatie/pdf-to-image

Convert a pdf to an image

1.4k15.2M64](/packages/spatie-pdf-to-image)[spatie/simple-excel

Read and write simple Excel and CSV files

1.4k9.9M48](/packages/spatie-simple-excel)[spatie/image

Manipulate images with an expressive API

1.4k54.4M138](/packages/spatie-image)[spatie/db-dumper

Dump databases

1.2k25.9M69](/packages/spatie-db-dumper)[spatie/laravel-pdf

Create PDFs in Laravel apps

9963.4M12](/packages/spatie-laravel-pdf)

PHPackages © 2026

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