This package is a wrapper for the TCPDF class that provides an elegant API for merging PDF files and returns a table of contents with bookmarks.
This library is based on the source code of: karriereat/pdf-merge
The same code structure was used and the functionality was added to make a bookmark in each added document, later it returns an array with the document's table of contents in order to render it in a JS engine on the frontend side.
You can install the package via composer:
composer require gabrielchavezme/pdf-table-of-content$pdfMerge = new PdfTableOfContent();
$pdfMerge->add([
'file' => '/path/to/file1.pdf',
'title' => 'File 1',
'id' => 1
]);
$pdfMerge->add([
'file' => '/path/to/file2.pdf',
'title' => 'File 2',
'id' => 2
]);
$pdfMerge->merge('/path/to/output.pdf');Please note, that the merge method will throw an NoFilesDefinedException if no files where added.
You can check if a file was already added for merging by calling:
$pdfMerge->contains('/path/to/file.pdf');Apache License 2.0 Please see LICENSE for more information.