lara-pdf-merger のインストール
1 |
$ composer require daltcore/lara-pdf-merger |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
Info from https://repo.packagist.org: #StandWithUkraine ./composer.json has been updated Running composer update daltcore/lara-pdf-merger Loading composer repositories with package information Updating dependencies Lock file operations: 1 install, 0 updates, 0 removals - Locking daltcore/lara-pdf-merger (2.0.6) Writing lock file Installing dependencies from lock file (including require-dev) Package operations: 1 install, 0 updates, 0 removals - Downloading daltcore/lara-pdf-merger (2.0.6) - Installing daltcore/lara-pdf-merger (2.0.6): Extracting archive Package daltcore/lara-pdf-merger is abandoned, you should avoid using it. No replacement was suggested. Package fabpot/goutte is abandoned, you should avoid using it. Use symfony/browser-kit instead. Generating optimized autoload files > Illuminate\Foundation\ComposerScripts::postAutoloadDump > @php artisan package:discover --ansi INFO Discovering packages. barryvdh/laravel-dompdf .............................................................................. DONE daltcore/lara-pdf-merger ............................................................................. DONE inertiajs/inertia-laravel ............................................................................ DONE kyslik/column-sortable ............................................................................... DONE laravel/sail ......................................................................................... DONE laravel/sanctum ...................................................................................... DONE laravel/tinker ....................................................................................... DONE maatwebsite/excel .................................................................................... DONE milon/barcode ........................................................................................ DONE nesbot/carbon ........................................................................................ DONE nunomaduro/collision ................................................................................. DONE nunomaduro/termwind .................................................................................. DONE spatie/laravel-ignition .............................................................................. DONE tightenco/ziggy ...................................................................................... DONE 96 packages you are using are looking for funding. Use the `composer fund` command to find out more! > @php artisan vendor:publish --tag=laravel-assets --ansi --force INFO No publishable resources for tag [laravel-assets]. No security vulnerability advisories found Using version ^2.0 for daltcore/lara-pdf-merger |
lara-pdf-merger の設定
config/app.php に、サービスプロバイダーを追加します。
1 2 3 4 5 6 7 8 9 |
'providers' => [ /* * Laravel Framework Service Providers... */ Illuminate\Auth\AuthServiceProvider::class, ・・・省略・・・ Illuminate\View\ViewServiceProvider::class, LynX39\LaraPdfMerger\PdfMergerServiceProvider::class, //追加 |
次にファサードの追加も行います。
1 2 3 4 5 6 7 8 |
'aliases' => [ 'App' => Illuminate\Support\Facades\App::class, ・・・省略・・・ 'View' => Illuminate\Support\Facades\View::class, 'PdfMerger' => LynX39\LaraPdfMerger\Facades\PdfMerger::class,//追加 ], |
サンプル
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
use LynX39\LaraPdfMerger\Facades\PdfMerger as PDFMerger; function sample() { $files = Storage::files('public'); $pdfMerger = PdfMerger::init(); foreach($files as $file){ $pdfMerger->addPDF(Storage::path($file)); } $pdfMerger->merge(); $pdfMerger->save(public_path("sample.pdf")); } |
参考サイト
Laravelを使ってPDFを結合する方法
https://reffect.co.jp/laravel/laravel-merge-pdf/
Laravel Merge Multiple PDF Files Example
https://www.itsolutionstuff.com/post/laravel-merge-multiple-pdf-files-exampleexample.html