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

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

spatie/pdf-to-text
==================

Extract text from a pdf

1.55.0(5mo ago)1.0k6.7M—8.1%13320MITPHPPHP ^8.4CI passing

Since Dec 31Pushed 5mo ago17 watchersCompare

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

READMEChangelog (10)Dependencies (3)Versions (19)Used By (20)

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)[![GitHub Workflow Status](https://camo.githubusercontent.com/0e49e24c5dba284f1b82ad32e47cb6c9662f4e557646fddc7131668b062d6a6b/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f7370617469652f7064662d746f2d746578742f72756e2d74657374732e796d6c3f6c6162656c3d7465737473)](https://camo.githubusercontent.com/0e49e24c5dba284f1b82ad32e47cb6c9662f4e557646fddc7131668b062d6a6b/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f7370617469652f7064662d746f2d746578742f72756e2d74657374732e796d6c3f6c6162656c3d7465737473)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)[![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).

Support us
----------

[](#support-us)

[![](https://camo.githubusercontent.com/a7778f1c5cf712550bbbf46f8a42494ff1c7e08edb8f8ac5269cede45ef14b29/68747470733a2f2f6769746875622d6164732e73332e65752d63656e7472616c2d312e616d617a6f6e6177732e636f6d2f7064662d746f2d746578742e6a70673f743d31)](https://spatie.be/github-ad-click/pdf-to-text)

We invest a lot of resources into creating [best in class open source packages](https://spatie.be/open-source). You can support us by [buying one of our paid products](https://spatie.be/open-source/support-us).

We highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using. You'll find our address on [our contact page](https://spatie.be/about-us). We publish all received postcards on [our virtual postcard wall](https://spatie.be/open-source/postcards).

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, CentOS, Rocky Linux or Fedora use this:

```
yum install poppler-utils
```

If you're on Windows you can download the [Xpdf command line tools](https://www.xpdfreader.com/download.html) and store its content at `C:\Program Files\xpdf-tools-win`.

The path to the `php2text.exe` executable should be `C:\Program Files\xpdf-tools-win\bin64\pdftotext.exe`.

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](https://github.com/spatie/.github/blob/main/CONTRIBUTING.md) for details.

Security
--------

[](#security)

If you've found a bug regarding security please mail  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

72

—

ExcellentBetter than 100% of packages

Maintenance70

Regular maintenance activity

Popularity69

Solid adoption and visibility

Community44

Growing community involvement

Maturity89

Battle-tested with a long release history

 Bus Factor1

Top contributor holds 54.5% 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 ~212 days

Recently: every ~178 days

Total

18

Last Release

175d ago

Major Versions

0.0.1 → 1.0.02015-12-31

PHP version history (5 changes)0.0.1PHP ^7.0

1.3.0PHP ^7.3

1.4.0PHP ^7.3|^8.0

1.5.0PHP ^7.4|^8.0

1.55.0PHP ^8.4

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/7535935?v=4)[Spatie](/maintainers/spatie)[@spatie](https://github.com/spatie)

---

Top Contributors

[![freekmurze](https://avatars.githubusercontent.com/u/483853?v=4)](https://github.com/freekmurze "freekmurze (79 commits)")[![nyamsprod](https://avatars.githubusercontent.com/u/51073?v=4)](https://github.com/nyamsprod "nyamsprod (16 commits)")[![nbayramberdiyev](https://avatars.githubusercontent.com/u/23094428?v=4)](https://github.com/nbayramberdiyev "nbayramberdiyev (11 commits)")[![AdrianMrn](https://avatars.githubusercontent.com/u/12762044?v=4)](https://github.com/AdrianMrn "AdrianMrn (7 commits)")[![alexmanase](https://avatars.githubusercontent.com/u/10696975?v=4)](https://github.com/alexmanase "alexmanase (6 commits)")[![sebastiandedeyne](https://avatars.githubusercontent.com/u/1561079?v=4)](https://github.com/sebastiandedeyne "sebastiandedeyne (4 commits)")[![Nielsvanpach](https://avatars.githubusercontent.com/u/10651054?v=4)](https://github.com/Nielsvanpach "Nielsvanpach (2 commits)")[![AlexVanderbist](https://avatars.githubusercontent.com/u/6287961?v=4)](https://github.com/AlexVanderbist "AlexVanderbist (2 commits)")[![enricodelazzari](https://avatars.githubusercontent.com/u/10452445?v=4)](https://github.com/enricodelazzari "enricodelazzari (2 commits)")[![peter279k](https://avatars.githubusercontent.com/u/9021747?v=4)](https://github.com/peter279k "peter279k (2 commits)")[![RayDabbah](https://avatars.githubusercontent.com/u/25418202?v=4)](https://github.com/RayDabbah "RayDabbah (2 commits)")[![stof](https://avatars.githubusercontent.com/u/439401?v=4)](https://github.com/stof "stof (2 commits)")[![angeljqv](https://avatars.githubusercontent.com/u/79208641?v=4)](https://github.com/angeljqv "angeljqv (1 commits)")[![thecaliskan](https://avatars.githubusercontent.com/u/13554944?v=4)](https://github.com/thecaliskan "thecaliskan (1 commits)")[![pich](https://avatars.githubusercontent.com/u/549441?v=4)](https://github.com/pich "pich (1 commits)")[![tanvir2sky](https://avatars.githubusercontent.com/u/13228343?v=4)](https://github.com/tanvir2sky "tanvir2sky (1 commits)")[![akr4m](https://avatars.githubusercontent.com/u/17238742?v=4)](https://github.com/akr4m "akr4m (1 commits)")[![sertxudev](https://avatars.githubusercontent.com/u/22801379?v=4)](https://github.com/sertxudev "sertxudev (1 commits)")[![srmklive](https://avatars.githubusercontent.com/u/839335?v=4)](https://github.com/srmklive "srmklive (1 commits)")[![jbraband](https://avatars.githubusercontent.com/u/1907283?v=4)](https://github.com/jbraband "jbraband (1 commits)")

---

Tags

pdfpdf-converterphptextspatiepdf-to-text

###  Code Quality

TestsPest

Code StyleLaravel Pint

### Embed Badge

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

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

###  Alternatives

[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)[spatie/laravel-health

Monitor the health of a Laravel application

86910.0M83](/packages/spatie-laravel-health)

PHPackages © 2026

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