viterbit / pdfimages-extractor
Extract images from pdf
Installs: 23 002
Dependents: 0
Suggesters: 0
Security: 0
Stars: 2
Watchers: 1
Forks: 0
Open Issues: 0
Requires
- php: ^7.3|^8.0
- symfony/process: ^4.0|^5.0|^6.0|^7.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^v2.19.2
- php-parallel-lint/php-var-dump-check: ^0.5.0
- phpstan/phpstan: ^0.12
- squizlabs/php_codesniffer: ^3.3
This package is auto-updated.
Last update: 2024-10-19 16:18:45 UTC
README
This package provides a class to extract images from a pdf.
use Viterbit\PdfImagesExtractor\Pdf; $images = Pdf::getImages('book.pdf'); //returns a FilesystemIterator
Requirements
Behind the scenes this package leverages pdfimages. You can verify if the binary installed on your system by issuing this command:
which pdfimages
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 or CentOS use this:
yum install poppler-utils
Installation
You can install the package via composer:
composer viterbit/pdfimages-extractor
Usage
Getting images from a pdf is easy.
$images = (new Pdf()) ->setPdf('book.pdf') ->images();
Or easier:
$images = Pdf::getImages('book.pdf');
By default the package will assume that the pdftoimages
command is located at /usr/bin/pdftoimages
.
If it is located elsewhere pass its binary path to constructor
$images = (new Pdf('/custom/path/to/pdftoimages')) ->setPdf('book.pdf') ->images();
or as the second parameter to the getImages
static method:
echo Pdf::getText('book.pdf', '/custom/path/to/pdftoimages');
Sometimes you may want to use pdfimages options. To do so you can set them up using the setOptions
method.
$images = (new Pdf()) ->setPdf('book.pdf') ->setOptions(['j', 'f 1']) ->images() ;
or as the third parameter to the getImages
static method:
$images = Pdf::getImages('book.pdf', null, ['j', 'f 1']);
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:
$images = (new Pdf()) ->setPdf('book.pdf') ->addOptions(['f 1']) ->images() ;
Change log
Please see CHANGELOG for more information about what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security
If you discover any security related issues, please email freek@spatie.be instead of using the issue tracker. design agency based in Antwerp, Belgium. You'll find an overview of all our open source projects on our website.
License
The MIT License (MIT). Please see License File for more information.