gabrielchavezme/pdf-table-of-content

1.0.5 2021-10-20 23:51 UTC

This package is auto-updated.

Last update: 2024-04-21 05:18:54 UTC


README

68747470733a2f2f6761627269656c63686176657a2e6d652f73746f726167652f323032312f30312f4c6f676f7469706f2d4761627269656c2d43686125434325383176657a2d30332d31303234783234302e706e67    

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.