iio/libmergepdf

Library for merging multiple PDFs

3.1.0 2017-10-31 19:31 UTC

README

Packagist Version Build Status Quality Score Dependency Status

PHP library for merging multiple PDFs using FPDI

Installation

Install using composer.

composer require iio/libmergepdf:^3.1

Usage

Append the first ten pages of bar.pdf to foo.pdf:

use iio\libmergepdf\Merger;
use iio\libmergepdf\Pages;

$merger = new Merger;
$merger->addFile('foo.pdf');
$merger->addFile('bar.pdf', new Pages('1-10'));
$createdPdf = $merger->merge();

Bulk add files from an iterator:

use iio\libmergepdf\Merger;
$merger = new Merger;
$merger->addIterator(['A.pdf', 'B.pdf']);
$createdPdf = $merger->merge();

Bulk add files using symfony finder:

use iio\libmergepdf\Merger;
use Symfony\Component\Finder\Finder;

$finder = new Finder;
$finder->files()->in(__DIR__)->name('*.pdf')->sortByName();

$merger = new Merger;
$merger->addFinder($finder);

$createdPdf = $merger->merge();

Known issues

  • Links and other content outside a page content stream is removed at merge. This is due to limitations in FPDI and not possible to resolve with the current strategy. For more information see FPDI.

Testing

Unit tests requires dependencies to be installed using composer:

composer install
vendor/bin/phpunit

Credits

libmergepdf is covered under the WTFPL.

@author Hannes Forsgård (hannes.forsgard@fripost.org)