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
Subscribe
Notify of
guest
1 Comment
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
joao
joao
2 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 https://www.setasign.com/fpdi-pdf-parser for more details)

1
0
Would love your thoughts, please comment.x
()
x