Looking to hire Laravel developers? Try LaraJobs

laravel-pdf-merger maintained by yaroslavpopovic

Description
Laravel PDF Merger based on TCPDF — fork of softplaceweb/laravel-10-pdf-merger with Laravel 11/12/13 support.
Authors
Yaroslav Popovic - Softplaceweb
Last update
2026/05/10 09:02 (dev-main)
License
Links
Downloads
3
Tags

Comments
comments powered by Disqus

Laravel PDF Merger based TCPDF

Latest Stable Version Total Downloads License

Fork of softplaceweb/laravel-10-pdf-merger with support for Laravel 11, 12 and 13.

A simple Laravel service provider with some basic configuration for including the TCPDF library to allow you to merge PDF's in your Laravel application.

Compatibility from 1.3 to 1.7 versions, if attempt to merge version greater than 1.4 it convert through Ghostscript.

The final result is a merged pdf file v 1.7

Requirements

  • PHP 8.2+
  • Laravel 11, 12 or 13
  • Ghostscript (gs command on Linux)

Installation

composer require yaroslavpopovic/laravel-pdf-merger

for lumen, you should add the following lines:

$app->register(Softplaceweb\PdfMerger\PdfMergerServiceProvider::class);
class_alias(Softplaceweb\PdfMerger\Facades\TCPDF::class, 'PDF');

That's it! You're good to go.

Here is a little example:

use Softplaceweb\PdfMerger\Facades\PdfMerger;

PdfMerger::addPDF('path/to/pdf1.pdf', 1)
->addPDF('path/to/pdf2.pdf', 'all')
->merge()
->save('new_file_name.pdf', 'browser');

or sending pdf's as array ...

use Softplaceweb\PdfMerger\Facades\PdfMerger;

PdfMerger::addPDF([
    [
        'filePath' => 'path/to/pdf1.pdf',
        'pages'    => 1,
    ],
    [
        'filePath' => 'path/to/pdf2.pdf',
    ],
])
->merge()
->save('new_file_name.pdf', 'browser');

You can extend functionality for this class and for a list of all available function take a look at the TCPDF Documentation

Configuration

Laravel Pdf Merger comes with some basic configuration. If you want to override the defaults, you can publish the config, like so:

php artisan vendor:publish --provider="Softplaceweb\PdfMerger\PdfMergerServiceProvider"

Now access config/pdf-merger.php to customize.

  • use_original_header is to used the original Header() from TCPDF.
    • Please note that PdfMerger::setHeaderCallback(function($pdf){}) overrides this settings.
  • use_original_footer is to used the original Footer() from TCPDF.
    • Please note that PdfMerger::setFooterCallback(function($pdf){}) overrides this settings.

Credits