gabrielchavezme / pdf-table-of-content
1.0.5
2021-10-20 23:51 UTC
Requires
- php: >=7.2
- tecnickcom/tcpdf: ^6.3
Requires (Dev)
- phpunit/phpunit: ^8.0 || ^9.0
- squizlabs/php_codesniffer: ^3.0
README
Pdf Merge & table of content Solution for PHP and Laravel
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.
Installation
You can install the package via composer:
composer require gabrielchavezme/pdf-table-of-content
Usage
$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.
Check for file existence
You can check if a file was already added for merging by calling:
$pdfMerge->contains('/path/to/file.pdf');
License
Apache License 2.0 Please see LICENSE for more information.