ottosmops/pdftotext

Extract text from PDF
153,725 5
Install
composer require ottosmops/pdftotext
Latest Version:2.0.1
PHP:>= 7.2
License:MIT
Last Updated:Sep 4, 2025
Links: GitHub  ·  Packagist
Maintainer: ottosmops

Extract text from a PDF with pdftotext

codecov Software License Latest Stable Version Packagist Downloads

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

\Ottosmops\Pdftotext\Extract::getText('/path/to/file.pdf') //returns the text from the pdf

Requirements

The Package uses pdftotext. Make sure that this is installed: which pdftotext

For Installation see: poppler-utils

If the installed binary is not found ("The command "which pdftotext" failed.") you can pass the full path to the _constructor (see below) or use putenv('PATH=$PATH:/usr/local/bin/:/usr/bin') (with the dir where pdftotext lives) before you call the class Extract.

Installation

composer require ottosmops/pdftotext

Usage

Extracting text from a pdf:

$text = (new Extract())
  ->pdf('file.pdf')
  ->text();

Security note: If you pass user input as options or filenames to the library, make sure to validate or escape them to avoid shell injection. The library uses symfony/process, which provides basic protection, but unsafe options could still cause issues.

You can set the binary and you can specify options:

$text = (new Extract('/path/to/pdftotext'))
  ->pdf('path/to/file.pdf')
  ->options('-layout')
  ->text();

Default options are: -eol unix -enc UTF-8 -raw

License

The MIT License (MIT). Please see License File for more information.

Related Packages

doctrine/dbal

Powerful PHP database abstraction layer (DBAL) with many features for database s...

637,827,751 9,703
laravel/framework

The Laravel Framework.

589,172,971 34,950
laravel/tinker

Powerful REPL for the Laravel framework.

498,216,183 7,442
laravel/serializable-closure

Laravel Serializable Closure provides an easy and secure way to serialize closur...

413,412,504 609
nunomaduro/collision

Cli error handling for console/command-line PHP applications.

391,429,217 4,660