GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - Escarter/poppler-wrapper-php: Laravel php wrapper for proppler utilities (pdftotext and pdfseparate)

BranchesTags
Open more actions menu

Latest commit

 

History

11 Commits
11 Commits

Folders and files

NameName
Last commit message
Last commit date
.github
.github
 
 
src
src
 
 
tests
tests
 
 
.editorconfig
.editorconfig
 
 
.gitattributes
.gitattributes
 
 
.gitignore
.gitignore
 
 
.php_cs.dist.php
.php_cs.dist.php
 
 
CHANGELOG.md
CHANGELOG.md
 
 
LICENSE.md
LICENSE.md
 
 
README.md
README.md
 
 
composer.json
composer.json
 
 
phpunit.xml.dist
phpunit.xml.dist
 
 
psalm.xml.dist
psalm.xml.dist
 
 

Repository files navigation

Extract text from pdf or separat a single pdf files to multiple files

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

use Escarter\PopplerPhp\PdfToText;
use Escarter\PopplerPhp\getOutput;

echo PdfToText::getText('document.pdf','/opt/homebrew/bin/pdftotext'); //returns the text from the pdf
echo PdfSeparate::getOutput('document.pdf','/opt/homebrew/bin/pdfseparate','destination_path/page_%d.pdf'); //returns null

Requirements

Behind the scenes this package leverages pdftotext and pdfseparate.You can verify if the binary installed on your system by issueing this command:

which pdftotext
which which pdfseparate

If they are installed the above commands 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 require escarter/poppler-wrapper-php

Usage Extracting text

Extracting text from a pdf is easy.

$text = (new PdfToText())
    ->setPdf('document.pdf')
    ->text();

Or easier:

echo PdfToText::getText('document.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 PdfToText('/custom/path/to/pdftotext'))
    ->setPdf('document.pdf')
    ->text();

or as the second parameter to the getText static method:

echo PdfToText::getText('document.pdf', '/custom/path/to/pdftotext');

Sometimes you may want to use pdftotext options. To do so you can set them up using the setOptions method.

$text = (new PdfToText())
    ->setPdf('table.pdf')
    ->setOptions(['layout', 'r 96'])
    ->text()
;

or as the third parameter to the getText static method:

echo PdfToText::getText('document.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 PdfToText())
    ->setPdf('table.pdf')
    ->setOptions(['layout', 'r 96'])
    ->addOptions(['f 1'])
    ->text()
;

Usage Separating Pdf into single files for each page

Separating a single pdf file into multiple files for each page.

 (new PdfSeparate())
    ->setPdf('document.pdf')
    ->setDestination('destination_path/page_%d.pdf')
    ->split();

Or easier:

 PdfSeparate::getOutput('document.pdf','destination_path/page_%d.pdf');

Once this is executed you can check in the destination_path to see all the splitted files (page_1.pdf, page_2.pdf....)

Change log

Please see CHANGELOG for more information about what has changed recently.

Testing

 composer test

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security related issues, please email [email protected] instead of using the issue tracker.

Credits

  • Escarter Mbutuh

License

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

About

Laravel php wrapper for proppler utilities (pdftotext and pdfseparate)

Resources

Readme
MIT license

Contributing

Contributing

Security policy

Security policy
Activity

Stars

5 stars

Watchers

1 watching

Forks

1 fork
Report repository

Releases

Sponsor this project

Packages

Used by

Contributors

Languages

You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.