Package

Webklex Laravel Pdfmerger

Generic PDF merger for Laravel

Package

webklex/laravel-pdfmerger

View on GitHub →

Laravel PDFMerger

Install

Via Composer

$ composer require webklex/laravel-pdfmerger

Setup

Add the service provider to the providers array in config/app.php.

'providers' => [
    ...
    Webklex\PDFMerger\Providers\PDFMergerServiceProvider::class
],

'aliases' => [
    ...
    'PDFMerger' => Webklex\PDFMerger\Facades\PDFMergerFacade::class
]

Usage

A basic usage example:

use Webklex\PDFMerger\Facades\PDFMergerFacade as PDFMerger;

$oMerger = PDFMerger::init();

$oMerger->addPDF('/path/to/project/vendors/webklex/laravel-pdfmerger/src/PDFMerger/examples/pdf_one.pdf', [2]);
$oMerger->addPDF('/path/to/project/vendors/webklex/laravel-pdfmerger/src/PDFMerger/examples/pdf_two.pdf', 'all');

$oMerger->merge();
$oMerger->save('merged_result.pdf');

...add raw content data:

$oMerger->addString(file_get_contents('/path/to/project/vendors/webklex/laravel-pdfmerger/src/PDFMerger/examples/pdf_two.pdf'), [1]);

...select the pages you want to merge:

$oMerger->addPDF($file, 'all');  //Add all pages
$oMerger->addPDF($file, [1]);    //Add page one only
$oMerger->addPDF($file, [2]);    //Add page two only
$oMerger->addPDF($file, [1, 3]); //Add page one and three only

...merge files together but add blank pages to support duplex printing:

$oMerger->duplexMerge();

...stream the merged content:

$oMerger->stream();

...download the merged content:

$oMerger->download();

..get the raw content data:

echo $oMerger->output();

...set the filename if you don't want to do it later:

$oMerger->setFileName('example.pdf');

Change log

Please see CHANGELOG for more information what has changed recently.

Testing

$ composer test

Security

If you discover any security related issues, please email github@webklex.com instead of using the issue tracker.

Credits

License

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

Webklex Laravel Pdfmerger Related Articles

2019 in Review image

2019 in Review

Read article
80 Laravel Tutorials, Packages, and Resources from 2016 image

80 Laravel Tutorials, Packages, and Resources from 2016

Read article
90 Laravel Tutorials, Packages, and Resources from 2023 image

90 Laravel Tutorials, Packages, and Resources from 2023

Read article
Laravel News 2025 Recap image

Laravel News 2025 Recap

Read article
Laravel News 2024 Recap image

Laravel News 2024 Recap

Read article
Laravel News 2023 Recap image

Laravel News 2023 Recap

Read article

PhpStorm

The go-to PHP IDE with extensive out-of-the-box support for Laravel and its ecosystem.

PhpStorm

Acquaint Softtech

Acquaint Softtech offers AI-ready Laravel developers who onboard in 48 hours at $3000/Month with no lengthy sales process and a 100 percent money-back guarantee.

Acquaint Softtech

Let your users buy domains without leaving your app

If your Laravel app gives users a site, a storefront, or a workspace, they’ll eventually want their own domain. The name.com API lets them search, register, and connect one without leaving your product. It’s a clean REST API, so Laravel’s HTTP client is all you need.

Let your users buy domains without leaving your app

Kirschbaum

Providing innovation and stability to ensure your web application succeeds.

Kirschbaum

Shift

Running an old Laravel version? Instant, automated Laravel upgrades and code modernization to keep your applications fresh.

Shift

Harpoon: Next generation time tracking and invoicing

The next generation time-tracking and billing software that helps your agency plan and forecast a profitable future.

Harpoon: Next generation time tracking and invoicing