PHPackages                             mishahawthorn/ocrmypdf - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. mishahawthorn/ocrmypdf

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

mishahawthorn/ocrmypdf
======================

A simple PHP wrapper for OCRmyPDF

v2.0.0(6d ago)101.7k↑25.6%2MITPHPPHP ^8.2CI passing

Since May 31Pushed 6d ago1 watchersCompare

[ Source](https://github.com/mishahawthorn/ocrmypdf-php)[ Packagist](https://packagist.org/packages/mishahawthorn/ocrmypdf)[ RSS](/packages/mishahawthorn-ocrmypdf/feed)WikiDiscussions main Synced yesterday

READMEChangelog (7)Dependencies (11)Versions (14)Used By (0)

ocrmypdf-php
============

[](#ocrmypdf-php)

A simple PHP wrapper for OCRmyPDF

[![Latest Stable Version](https://camo.githubusercontent.com/12cb407b7d3e4f9abf41e4961c3fc1f2a5c3b23d57201dc979fe71627efe65ae/687474703a2f2f706f7365722e707567782e6f72672f6d6973686168617774686f726e2f6f63726d797064662f76)](https://packagist.org/packages/mishahawthorn/ocrmypdf)[![Total Downloads](https://camo.githubusercontent.com/6d3651ec5c670bd48360f728993417c480d0dcd3b38ba7f1803ae674c51a764f/687474703a2f2f706f7365722e707567782e6f72672f6d6973686168617774686f726e2f6f63726d797064662f646f776e6c6f616473)](https://packagist.org/packages/mishahawthorn/ocrmypdf)[![License](https://camo.githubusercontent.com/e498af3edcbb778e5f0fc0193065a52b523fbb4abe4d7aa709a95b42abd7e637/687474703a2f2f706f7365722e707567782e6f72672f6d6973686168617774686f726e2f6f63726d797064662f6c6963656e7365)](https://packagist.org/packages/mishahawthorn/ocrmypdf)[![PHP Version Require](https://camo.githubusercontent.com/9c88f3396f034611237286a75e9a35ef8f170f855e1d3b4c774ec66fd04e4967/687474703a2f2f706f7365722e707567782e6f72672f6d6973686168617774686f726e2f6f63726d797064662f726571756972652f706870)](https://packagist.org/packages/mishahawthorn/ocrmypdf)[![codecov](https://camo.githubusercontent.com/b53d0b7b5e6170c045665b83b8b40c849eacc21b72cdd71ad773ad3e152568fb/68747470733a2f2f636f6465636f762e696f2f67682f6d6973686168617774686f726e2f6f63726d797064662d7068702f67726170682f62616467652e7376673f746f6b656e3d463343553954384c4a55)](https://codecov.io/gh/mishahawthorn/ocrmypdf-php)

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

[](#installation)

Via [Composer](http://getcomposer.org/):

```
$ composer require mishahawthorn/ocrmypdf

```

**This library depends on [OCRmyPDF](https://github.com/jbarlow83/OCRmyPDF).** Please see the GitHub repository for instructions on how to install OCRmyPDF on your platform.

Usage
-----

[](#usage)

### Basic example

[](#basic-example)

```
use mishahawthorn\OCRmyPDF\OCRmyPDF;

//Return file path of outputted, OCRed PDF
echo OCRmyPDF::make('document.pdf')->run();

//Return file contents of outputted, OCRed PDF
echo OCRmyPDF::make('scannedImage.png')->setOutputPDFPath(null)->run();
```

API
---

[](#api)

### setParam

[](#setparam)

Define invocation parameters for `ocrmypdf`. See `ocrmypdf --help` for a list of available parameters.

Important

Parameters configured via `setParam` will override any other parameters or configurations set otherwise.

```
use mishahawthorn\OCRmyPDF\OCRmyPDF;

//Passing a single parameter with a value
OCRmyPDF::make('document_zh-CN.pdf')
    ->setParam('-l', 'chi_sim')
    ->run();

//Passing a single parameter without a value
OCRmyPDF::make('document_withBackground.pdf')
    ->setParam('--remove-background')
    ->run();

//Passing multiple parameters
OCRmyPDF::make('document_withoutAttribution.pdf')
    ->setParam('--title', 'Lorem Ipsum')
    ->setParam('--keywords', 'Lorem,Ipsum,dolor,sit,amet')
    ->run();
```

### setInputData

[](#setinputdata)

Pass image/PDF data loaded in memory into `ocrmypdf` directly via stdin.

```
use mishahawthorn\OCRmyPDF\OCRmyPDF;

//Using Imagick
$data = $img->getImageBlob();
$size = $img->getImageLength();

//Using GD
ob_start();
imagepng($img, null, 0);
$size = ob_get_length();
$data = ob_get_clean();

OCRmyPDF::make()
    ->setInputData($data, $size)
    ->run();
```

### setOutputPDFPath

[](#setoutputpdfpath)

Specify a writable path where `ocrmypdf` should generate output PDF.

```
use mishahawthorn\OCRmyPDF\OCRmyPDF;
OCRmyPDF::make('document.pdf')
    ->setOutputPDFPath('/outputDir/ocr_document.pdf')
    ->run();
```

### setExecutable

[](#setexecutable)

Define a custom location of the `ocrmypdf` executable, if by any reason it is not present in the `$PATH`.

```
use mishahawthorn\OCRmyPDF\OCRmyPDF;
OCRmyPDF::make('document.pdf')
    ->setExecutable('/path/to/ocrmypdf')
    ->run();
```

### extractText / getText

[](#extracttext--gettext)

Write the recognized plaintext to a sidecar file and read it back after `run()`. Call `extractText()` with no argument to use a temporary file that is read and discarded, or pass a path to keep the text file.

```
use mishahawthorn\OCRmyPDF\OCRmyPDF;

$ocr = OCRmyPDF::make('document.pdf')
    ->language('eng')
    ->extractText();

$pdfPath = $ocr->run();
$text = $ocr->getText(); //Recognized plaintext
```

### Convenience setters

[](#convenience-setters)

Thin, type-safe wrappers over the most common `ocrmypdf` parameters. Each is equivalent to the matching `setParam` call.

```
use mishahawthorn\OCRmyPDF\OCRmyPDF;

OCRmyPDF::make('document.pdf')
    ->language('eng', 'deu') // -l eng+deu
    ->deskew()               // --deskew
    ->rotatePages()          // --rotate-pages
    ->clean()                // --clean
    ->removeBackground()     // --remove-background
    ->optimize(3)            // --optimize 3 (0-3)
    ->skipText()             // --skip-text  (or ->forceOcr() / ->redoOcr())
    ->setThreadLimit(4)      // --jobs 4
    ->setTempDir('/var/tmp')
    ->run();
```

Boolean setters accept `false` to remove the flag, e.g. `->deskew(false)`.

### setTimeout

[](#settimeout)

Terminate the `ocrmypdf` process if it runs longer than the given number of seconds. A `ProcessTimeoutException` is thrown when the limit is exceeded.

```
use mishahawthorn\OCRmyPDF\OCRmyPDF;

OCRmyPDF::make('document.pdf')
    ->setTimeout(120) //seconds
    ->run();
```

### setLogger

[](#setlogger)

Attach any [PSR-3](https://www.php-fig.org/psr/psr-3/) logger to receive the generated command, stderr output and any failures.

```
use mishahawthorn\OCRmyPDF\OCRmyPDF;

OCRmyPDF::make('document.pdf')
    ->setLogger($psr3Logger)
    ->run();
```

License
-------

[](#license)

ocrmypdf-php is released under the [MIT License](https://github.com/mishahawthorn/ocrmypdf-php/blob/main/LICENSE).

Credits
-------

[](#credits)

Development of ocrmypdf-php is based on the [tesseract-ocr-for-php](https://github.com/thiagoalessio/tesseract-ocr-for-php) PHP wrapper library for `tesseract`developed by [thiagoalessio](https://github.com/thiagoalessio) and associated contributors.

###  Health Score

56

—

FairBetter than 97% of packages

Maintenance98

Actively maintained with recent releases

Popularity28

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity72

Established project with proven stability

 Bus Factor1

Top contributor holds 77.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 ~309 days

Recently: every ~230 days

Total

7

Last Release

6d ago

Major Versions

v0.4.0 → v1.0.02025-10-08

v1.0.0 → v2.0.02026-06-27

PHP version history (2 changes)0.1.0PHP ^8.0

v2.0.0PHP ^8.2

### Community

Maintainers

![](https://www.gravatar.com/avatar/a5fa68fd562efc5ddae55c585124ce914209807a6ddbb8f6a3a44f3d3a2a5eeb?d=identicon)[mishahawthorn](/maintainers/mishahawthorn)

---

Top Contributors

[![mishahawthorn](https://avatars.githubusercontent.com/u/6118330?v=4)](https://github.com/mishahawthorn "mishahawthorn (38 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (11 commits)")

---

Tags

phpwrapperOCRocrmypdf

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/mishahawthorn-ocrmypdf/health.svg)

```
[![Health](https://phpackages.com/badges/mishahawthorn-ocrmypdf/health.svg)](https://phpackages.com/packages/mishahawthorn-ocrmypdf)
```

###  Alternatives

[ecotone/ecotone

Enterprise architecture layer for Laravel and Symfony — CQRS, Event Sourcing, Durable Workflows (Sagas, Orchestrators), Projections, and Outbox messaging via PHP attributes.

564576.7k52](/packages/ecotone-ecotone)[jaxon-php/jaxon-core

Jaxon is an open source PHP library for easily creating Ajax web applications

74149.4k30](/packages/jaxon-php-jaxon-core)[zoon/rialto

Manage Node resources from PHP

12250.6k3](/packages/zoon-rialto)[dagger/dagger

Dagger PHP SDK

261.1k](/packages/dagger-dagger)

PHPackages © 2026

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