serhiikamolov / laravel-pdfmerger
Generic PDF merger for Laravel
v1.0.0
2023-01-23 15:02 UTC
Requires
- php: >=5.5.9
- illuminate/support: >=5.0
- setasign/fpdf: 1.8.*
- setasign/fpdi: ^2.0
Requires (Dev)
- phpunit/phpunit: 4.*
- scrutinizer/ocular: ~1.1
- squizlabs/php_codesniffer: ~2.3
This package is auto-updated.
Last update: 2024-10-23 18:48:17 UTC
README
Install
Via Composer
$ composer require serhiikamolov/laravel-pdfmerger
Setup
Add the service provider to the providers array in config/app.php
.
'providers' => [ ... PDFMerger\Providers\PDFMergerServiceProvider::class ], 'aliases' => [ ... 'PDFMerger' => PDFMerger\Facades\PDFMergerFacade::class ]
Usage
A basic usage example:
use PDFMerger\Facades\PDFMergerFacade as PDFMerger; $oMerger = PDFMerger::init(); $oMerger->addPDF('/path/to/project/vendors/webklex/laravel-pdfmerger/src/PDFMerger/examples/pdf_one.pdf', [2]); $oMerger->addPDF('/path/to/project/vendors/webklex/laravel-pdfmerger/src/PDFMerger/examples/pdf_two.pdf', 'all'); $oMerger->merge(); $oMerger->save('merged_result.pdf');
...add raw content data:
$oMerger->addString(file_get_contents('/path/to/project/vendors/webklex/laravel-pdfmerger/src/PDFMerger/examples/pdf_two.pdf'), [1]);
...select the pages you want to merge:
$oMerger->addPDF($file, 'all'); //Add all pages $oMerger->addPDF($file, [1]); //Add page one only $oMerger->addPDF($file, [2]); //Add page two only $oMerger->addPDF($file, [1, 3]); //Add page one and three only
...merge files together but add blank pages to support duplex printing:
$oMerger->duplexMerge();
...stream the merged content:
$oMerger->stream();
...download the merged content:
$oMerger->download();
..get the raw content data:
echo $oMerger->output();
...set the filename if you don't want to do it later:
$oMerger->setFileName('example.pdf');
Credits
- [Webklex][link-author]
- All Contributors
License
The MIT License (MIT). Please see License File for more information.