mamura/pdf-combine
最新稳定版本:0.1.0
Composer 安装命令:
composer require mamura/pdf-combine
包简介
Package for combining PDF files in PHP
README 文档
README
Combine PDF files in PHP and Laravel with optional page numbering.
Installation
composer require mamura/pdf-combine
Basic Usage (PHP)
use Mamura\PdfCombine\DTO\CombinePdfData; use Mamura\PdfCombine\Services\CombineDocuments; use Mamura\PdfCombine\Services\Drivers\FpdiPdfCombiner; $service = new CombineDocuments(new FpdiPdfCombiner()); $output = $service->handle( new CombinePdfData( files: [ '/path/one.pdf', '/path/two.pdf', ], outputPath: '/path/merged.pdf', addPageNumbers: true ) ); echo $output;
Laravel Usage
This package supports Laravel auto-discovery.
use Mamura\PdfCombine\DTO\CombinePdfData; use Mamura\PdfCombine\Services\CombineDocuments; $path = app(CombineDocuments::class)->handle( new CombinePdfData( files: [ storage_path('app/a.pdf'), storage_path('app/b.pdf'), ], addPageNumbers: true ) ); return response()->json([ 'file' => $path, ]);
CombinePdfData
| Field | Type | Description |
|---|---|---|
| files | array | List of PDF file paths |
| outputPath | ?string | Output file path (optional) |
| addPageNumbers | bool | Add page numbers to the final PDF |
Notes
filesmust contain valid paths to readable PDF files.- If
outputPathis not provided, a temporary file will be generated automatically. - Page numbers are rendered at the bottom center of each page when enabled.
Exceptions
The package may throw:
Mamura\PdfCombine\Exceptions\FileNotFoundExceptionMamura\PdfCombine\Exceptions\InvalidPdfExceptionMamura\PdfCombine\Exceptions\PdfCombineException
Example:
try { $service->handle($data); } catch (\Mamura\PdfCombine\Exceptions\PdfCombineException $e) { // handle error }
Testing
Run tests with:
vendor/bin/phpunit
Current Limitations
- Supports only local PDF files
- Uses FPDI as the current driver
- Does not support remote files or cloud storage (S3, etc.)
- Does not perform OCR or PDF validation beyond basic checks
Roadmap
- Configurable page number position
- Custom font support
- Multiple drivers (external APIs, fallback strategies)
- Stream output support (without saving to disk)
License
MIT
统计信息
- 总下载量: 0
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 6
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-04-22