PHPackages                             metolabs/text-extractor-php - 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. [Image &amp; Media](/categories/media)
4. /
5. metolabs/text-extractor-php

ActiveLibrary[Image &amp; Media](/categories/media)

metolabs/text-extractor-php
===========================

PHP wrapper for extracting text from PDF documents and images

1.0.0(1y ago)023↓90%MITPHPPHP &gt;=8.0

Since Jun 12Pushed 1y agoCompare

[ Source](https://github.com/MetoLabs/text-extractor-php)[ Packagist](https://packagist.org/packages/metolabs/text-extractor-php)[ RSS](/packages/metolabs-text-extractor-php/feed)WikiDiscussions master Synced 3w ago

READMEChangelogDependencies (4)Versions (2)Used By (0)

MetoLabs Text Extractor
=======================

[](#metolabs-text-extractor)

[![License: MIT](https://camo.githubusercontent.com/8bb50fd2278f18fc326bf71f6e88ca8f884f72f179d3e555e20ed30157190d0d/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d677265656e2e737667)](LICENSE)

A PHP library to extract text from PDFs and images using Spatie's PDF utilities and Tesseract OCR. Supports multiple extraction modes: text-based, OCR, or automatic.

Features
--------

[](#features)

- Extract text from PDF using `spatie/pdf-to-text`
- Convert PDF to images using `spatie/pdf-to-image` and apply OCR
- Extract from images directly using `thiagoalessio/tesseract_ocr`
- Automatic mode: falls back to OCR if text extraction fails
- Configurable extraction settings

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

[](#installation)

```
composer require metolabs/text-extractor
```

Usage
-----

[](#usage)

### Basic usage

[](#basic-usage)

```
use MetoLabs\TextExtractor\TextExtractor;

$text = TextExtractor::from('example.pdf');
echo $text;
```

### Extract from image

[](#extract-from-image)

```
$text = TextExtractor::from('example.png');
```

### Use specific mode

[](#use-specific-mode)

```
$extractor = TextExtractor::make('example.pdf', TextExtractor::MODE_TEXT);
$extractor->extract();
echo $extractor->getText();
```

### Configure OCR and resolution

[](#configure-ocr-and-resolution)

```
use MetoLabs\TextExtractor\Configurations\PdfToImageConfiguration;
use MetoLabs\TextExtractor\Configurations\TesseractConfiguration;

$config = [
    'pdftoimage' => (new PdfToImageConfiguration())->setResolution(300),
    'tesseract' => (new TesseractConfiguration())->set('options', [
        'lang' => 'eng',
    ]),
];

$extractor = TextExtractor::make('example.pdf', TextExtractor::MODE_OCR, $config);
$extractor->extract();
echo $extractor->getText();
```

### Extract specific pages

[](#extract-specific-pages)

```
use MetoLabs\TextExtractor\Configurations\PdfToImageConfiguration;

$config = [
    'pdftoimage' => (new PdfToImageConfiguration())->setPages([1, 3, 5]),
];

$extractor = TextExtractor::make('example.pdf', TextExtractor::MODE_AUTO, $config);
$extractor->extract();
echo $extractor->getText();
```

Modes
-----

[](#modes)

- `TextExtractor::MODE_TEXT` – Uses `pdftotext` for extraction.
- `TextExtractor::MODE_OCR` – Converts PDF to images and uses OCR.
- `TextExtractor::MODE_AUTO` – Tries `pdftotext`, falls back to OCR if it fails.

Exceptions
----------

[](#exceptions)

- `MissingInputFileException`
- `InvalidModeException`
- `TextExtractionFailedException`
- Any exceptions from Spatie or Tesseract OCR libraries

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

[](#requirements)

- PHP 8.0+
- `pdftotext` and `pdftoppm` must be installed and accessible in system path
- `tesseract` OCR must be installed

License
-------

[](#license)

MIT License

Copyright (c) 2025 Gerardo Ramirez

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

\*\*THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

###  Health Score

28

—

LowBetter than 52% of packages

Maintenance49

Moderate activity, may be stable

Popularity7

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity42

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

376d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/9123134?v=4)[Gerardo Ramirez](/maintainers/geradrum)[@geradrum](https://github.com/geradrum)

---

Top Contributors

[![geradrum](https://avatars.githubusercontent.com/u/9123134?v=4)](https://github.com/geradrum "geradrum (1 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/metolabs-text-extractor-php/health.svg)

```
[![Health](https://phpackages.com/badges/metolabs-text-extractor-php/health.svg)](https://phpackages.com/packages/metolabs-text-extractor-php)
```

###  Alternatives

[goat1000/svggraph

Generates SVG graphs

133890.0k3](/packages/goat1000-svggraph)[finller/laravel-media

A flexible media library for Laravel

472.1k](/packages/finller-laravel-media)[elegantly/laravel-media

A flexible media library for Laravel

475.6k4](/packages/elegantly-laravel-media)

PHPackages © 2026

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