- Install this library with composer
composer require virdiggg/merge-files
- Create function to call this library
<?php
require_once __DIR__ . '/../vendor/autoload.php';
use Virdiggg\MergeFiles\Merge;
try {
$mf = new Merge();
$mf->setAuthor('Me');
$mf->setCreator('Also Me');
$mf->setOutputName('mergedpdf.pdf');
$mf->setOutputPath(__DIR__ . '/output/');
// $mf->setKeywords(['pdf', 'word', 'excel', 'image']);
$mf->setTitle('Merged PDF'); // Mandatory
$mf->setSubject('Merged PDF'); // Mandatory
// $mf->setPassword('password');
$files = [
__DIR__.'/input/Book1.xlsx',
__DIR__.'/input/download.pdf',
__DIR__.'/input/word.docx',
__DIR__.'/input/img.jpg'
];
$mf->mergeToPDF($files);
} catch (Exception $e) {
echo "Error: " . $e->getMessage();
}