GithubHelp home page GithubHelp logo

poppler-php's Introduction

PopplerPhp: Comprehensive PHP wrapper for Poppler-utils

PopplerPhp is a complete and very flexible PHP wrapper for Poppler-utils. This package is brought to you so you can use php and poppler-utils to extract contents from, and convert your pdf files to any of these formats:

  • HTML
  • JPG, PNG, TIFF
  • PostScript (PS)
  • Encapsulated PostScript (EPS)
  • Scalable Vector Graphic (SVG)
  • Plain Text

You can also use this package to split pdf files, combine pdf files, and detach embedded items from pdf files using within your php scripts. With the NcJoes\PopplerPhp\PdfInfo class, you can query meta-data of any pdf file.

Important Notes

Installation

It is recommended to install Poppler-PHP through Composer.

Run this command within your project directory

composer require ncjoes/poppler-php

Or add this line to your composer.json

{
	"ncjoes/poppler-php": "0.1.*"
}

Dependencies

In order to use Poppler-PHP, you need to install Poppler. Depending of your configuration, please follow the instructions at http://poppler.freedesktop.org/. You will also need to configure your PHP environment to enable shell access.

Briefly,

If you are using Ubuntu Distro, just install it from apt:

sudo apt-get install poppler-utils

For Windows Users

First download poppler-utils for windows here http://blog.alivate.com.au/poppler-windows/.

Extract the downloaded archive and copy the contents of the bin directory to your-project-path/vendor/bin/poppler/.

For OS/X Users

1. Install brew

Brew is a famous package manager on OS/X : http://brew.sh/ (aptitude style).

2. Install poppler

brew install poppler

Usage

Here are some samples.

<?php
// if you are using composer, just use this
use NcJoes\PopplerPhp\PdfInfo;
use NcJoes\PopplerPhp\Config;
use NcJoes\PopplerPhp\PdfToCairo;
use NcJoes\PopplerPhp\PdfToHtml;
use NcJoes\PopplerPhp\Constants as C;

// set Poppler utils binary location
Config::setBinDirectory('C:/path-to-project/vendor/bin/poppler');

// set output directory
Config::setOutputDirectory('C:/path-to-project/storage/poppler-output');


// get pdf meta-data
$pdf = new PdfInfo('path-to-file\file.pdf');
$info = $pdf->getInfo(); //returns an associative array
$authors = $pdf->getAuthors();
//...e.t.c.

//Convert PDF document to various image formats
$cairo1 = new PdfToCairo(__DIR__.'/sources/test1.pdf');
$cairo2 = clone $cairo1;
$cairo3 = clone $cairo1;
$cairo4 = clone $cairo1;
$cairo5 = clone $cairo1;
$cairo6 = clone $cairo1;

$cairo1->firstPageOnly();
$cairo1->generatePNG();

$cairo2->firstPageOnly();
$cairo2->generateJPG();

//$cairo3->firstPageOnly();
//$cairo3->generateTIFF();
//PDT to TIFF conversion is not working at the moment, hope to fix it soon

$cairo4->startFromPage(1)->stopAtPage(1);
$cairo4->generatePS();

$cairo5->setPostScriptLevel(C::_LEVEL3)->startFromPage(1)->stopAtPage(1);
$cairo5->generateEPS();

$cairo6->startFromPage(1)->stopAtPage(2);
$cairo6->generateSVG();

//generate HTML
$pdfToHtml = new PdfToHtml(__DIR__.'/tests/sources/test1.pdf');
$pdfToHtml->setZoomRatio(1.8);
$pdfToHtml->exchangePdfLinks();
$pdfToHtml->startFromPage(1)->stopAtPage(5);
$pdfToHtml->generateSingleDocument();
$pdfToHtml->noFrames();
$pdfToHtml->oddPagesOnly();
$pdfToHtml->outputToConsole();
print_r($pdfToHtml->generate()); //html string

?>

License

The PopplerPHP package is open-sourced software licensed under the MIT license.

Feedback & Contribute

Notify me of any issues, bugs, or improvements. Thanks ๐Ÿ‘

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.