PHP | How to merge multiple PDFs into single file using pdftk

Author - Webner

Using PDFtk we can merge multiple files into a single file using a command like this:

Example : pdftk file1 file2 output file3.

Sample code to accomplish the same using PHP is given below:

$arrayOfPDFFiles;
$outputPDFName = “mergeResult.pdf”;
$dir =”Files/GeneratedPDFs/”;
for($i =0;$i<sizeOf($arrayOfPDFFiles);$i++)
{
$multiplePDFs = $multiplePDFs.” “.$dir.$arrayOfPDFFiles[$i];
}
$command = 'pdftk '.$multiplePDFs .” output “.$dir.$outputName;
passthru($command);

Note : For this code to work, please make sure pdftk is installed on your system.

Webner Solutions is a Software Development company focused on developing CRM apps (Salesforce, Zoho), LMS Apps (Moodle/Totara), Websites and Mobile apps. If you need Web development or any other software development assistance please contact us at webdevelopment@webners.com

Webner Solutions is a Software Development company focused on developing Insurance Agency Management Systems, Learning Management Systems and Salesforce apps. Contact us at dev@webners.com for your Insurance, eLearning and Salesforce applications.

Leave a Reply

Your email address will not be published. Required fields are marked *