How to Merge PDF Files using Laravel, PHP

/ By Arjun / Published on September 3, 2021
Laravel merge pdfs

In this tutorial, you will learn how to merge multiple pdf files in your Laravel application. We gonna write a simple PHP script to merge one or more pdf files (Laravel merge pdfs), into a single file. This script will work with any version of the Laravel framework.

We gonna install the setasign\Fpdi library using composer and we’ll be using it to merge multiple pdf files into a single file.

Let’s start implementing it by installing the Laravel framework. This tutorial assumes that your computer already has PHP and Composer installed.

Step 1: Install Laravel framework with the composer.
you can create a new Laravel project by using Composer directly with the below command. After the application has been created, you may start Laravel’s local development server using the Artisan CLI’s serve command as shown below.

Step 2: Install FPDI Package using composer

Step 3: Open the existing controller file or create a new controller with php artisan make:controller MergePDFController command and copy below methods to it.

Step 4: Define a route in web.php to test the functions.

Step5: Now start your application with php artisan serve and access it at http://localhost:8000/merge-pdfs

You can see the output files at:

I hope you like this Post, Please feel free to comment below, your suggestion and problems if you face - we are here to solve your problems.

0 0 votes
Article Rating
Notify of
1 Comment
Newest Most Voted
Inline Feedbacks
View all comments
3 months ago

setasign\Fpdi\PdfParser\CrossReference\CrossReferenceExceptionThis PDF document probably uses a compression technique which is not supported by the free parser shipped with FPDI. (See for more details)

Would love your thoughts, please comment.x