PHPackages                             tudorr89/pdfcombiner - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [PDF &amp; Document Generation](/categories/documents)
4. /
5. tudorr89/pdfcombiner

ActiveLibrary[PDF &amp; Document Generation](/categories/documents)

tudorr89/pdfcombiner
====================

A modern PHP package to combine multiple PDF files with page-level granularity. Supports Laravel auto-discovery and standalone usage.

v2.0.1(2mo ago)012MITPHPPHP ^8.2

Since May 15Pushed 2mo agoCompare

[ Source](https://github.com/tudorr89/pdfcombiner)[ Packagist](https://packagist.org/packages/tudorr89/pdfcombiner)[ RSS](/packages/tudorr89-pdfcombiner/feed)WikiDiscussions main Synced 3w ago

READMEChangelog (1)Dependencies (6)Versions (4)Used By (0)

PDF Combine
===========

[](#pdf-combine)

[![Latest Version](https://camo.githubusercontent.com/46e07f72a9021f29b8a1b9274e19dc7046c3b42bb7d3de78046434b6e1f965d4/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f7475646f727238392f706466636f6d62696e65722e737667)](https://packagist.org/packages/tudorr89/pdfcombiner)[![License](https://camo.githubusercontent.com/5745d9cd0a7473a8370fe5a7237f16a550a11cff5db147507aad8d2cd8d99ec6/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f7475646f727238392f706466636f6d62696e65722e737667)](https://github.com/tudorr89/pdfcombiner/blob/main/LICENSE)[![PHP Version](https://camo.githubusercontent.com/3b058dfffd7e76ab21385957b644fb1cec5e0e0f07ceb78223c05feb4a2b54ad/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f7475646f727238392f706466636f6d62696e65722e737667)](https://packagist.org/packages/tudorr89/pdfcombiner)

A modern PHP package to combine multiple PDF files with page-level granularity. Built on TCPDF and FPDI for reliable rendering. Supports Laravel auto-discovery (10.x, 11.x, 12.x) and standalone usage.

---

Requirements
------------

[](#requirements)

- **PHP** `^8.2`
- **Composer**

Under the hood the package depends on [`tecnickcom/tcpdf`](https://github.com/tecnickcom/TCPDF) and [`setasign/fpdi`](https://github.com/Setasign/FPDI) — both are pulled in automatically.

Installation
------------

[](#installation)

```
composer require tudorr89/pdfcombiner
```

### Laravel

[](#laravel)

If you use Laravel ≥ 5.5 the package registers itself via auto-discovery. No manual setup required.

**Publish the config** (optional):

```
php artisan vendor:publish --tag=pdfcombine-config
```

### Standalone (non-Laravel)

[](#standalone-non-laravel)

```
require 'vendor/autoload.php';

use PdfCombine\PDFCombiner;

$combiner = new PDFCombiner;
```

---

Quick Start
-----------

[](#quick-start)

### Combine two files and save to disk

[](#combine-two-files-and-save-to-disk)

```
$combiner = new \PdfCombine\PDFCombiner();

$combiner
    ->addFile('/path/to/report.pdf')
    ->addFile('/path/to/appendix.pdf')
    ->save('/path/to/combined.pdf');
```

### Combine specific pages only

[](#combine-specific-pages-only)

```
$combiner
    ->addFile('/path/to/large.pdf', [1, 5, 7])  // pages 1, 5, 7
    ->addFile('/path/to/summary.pdf')            // all pages
    ->save('/path/to/result.pdf');
```

### Stream to browser for download

[](#stream-to-browser-for-download)

```
$combiner
    ->addFile('/path/to/doc.pdf')
    ->addRaw($pdfBinaryString, 'attachment.pdf')
    ->download('final-report.pdf');
```

### Get PDF contents as a string

[](#get-pdf-contents-as-a-string)

```
$content = $combiner
    ->addFile('/path/to/doc.pdf')
    ->blob();

// or
$content = $combiner->stream();
```

### Laravel — Dependency Injection

[](#laravel--dependency-injection)

```
use PdfCombine\Contracts\PDFCombinerInterface;

class ReportController
{
    public function combine(PDFCombinerInterface $combiner)
    {
        $combiner
            ->addFile(storage_path('reports/january.pdf'))
            ->addFile(storage_path('reports/february.pdf'))
            ->save(storage_path('reports/q1.pdf'));

        return response()->download(storage_path('reports/q1.pdf'));
    }
}
```

### Laravel — Facade

[](#laravel--facade)

```
use PDFCombine;

PDFCombine::addFile('/path/to/a.pdf')
    ->addFile('/path/to/b.pdf')
    ->download('combined.pdf');
```

---

API Reference
-------------

[](#api-reference)

### `addFile(string $path, array $pages = []): self`

[](#addfilestring-path-array-pages---self)

Add a PDF file from disk.

- `$path` — absolute or relative path to a `.pdf` file
- `$pages` — optional array of page numbers to include (1-indexed). Empty array = all pages.

```
$combiner->addFile('/path/to/doc.pdf');                // all pages
$combiner->addFile('/path/to/doc.pdf', [1, 3]);        // pages 1 and 3 only
$combiner->addFile('/path/to/doc.pdf', range(5, 10));  // pages 5 through 10
```

### `addFiles(array $paths): self`

[](#addfilesarray-paths-self)

Add multiple files at once. Accepts plain paths or `[path, pages]` tuples.

```
$combiner->addFiles([
    '/path/to/cover.pdf',
    ['/path/to/body.pdf', [1, 2, 3]],
    '/path/to/back.pdf',
]);
```

### `addRaw(string $content, string $filename = 'document.pdf', array $pages = []): self`

[](#addrawstring-content-string-filename--documentpdf-array-pages---self)

Add PDF content from a raw binary string (e.g. from an HTTP response, database BLOB, or upload stream).

```
$rawPdf = file_get_contents('https://example.com/remote.pdf');
$combiner->addRaw($rawPdf, 'remote.pdf');
```

### `save(string $outputPath): bool`

[](#savestring-outputpath-bool)

Combine all added files and write the result to `$outputPath`. Returns `true` on success.

```
$combiner->addFile('a.pdf')->addFile('b.pdf')->save('combined.pdf');
```

### `download(string $filename = 'combined.pdf'): void`

[](#downloadstring-filename--combinedpdf-void)

Send the combined PDF to the browser as a download (sends `Content-Disposition: attachment` headers + body). Does **not** call `exit` — middleware and terminating callbacks still run.

```
$combiner->download('quarterly-report.pdf');
```

> In Laravel, prefer streaming the body yourself so you stay on the full response pipeline:
>
> ```
> return response()->streamDownload(
>     fn () => print($combiner->stream()),
>     'quarterly-report.pdf',
>     ['Content-Type' => 'application/pdf'],
> );
> ```

### `stream(string $filename = 'combined.pdf'): string`

[](#streamstring-filename--combinedpdf-string)

Return the combined PDF as a raw binary string.

```
$pdf = $combiner->stream();
// store in S3, send via email attachment, etc.
```

### `blob(): string`

[](#blob-string)

Alias for `stream()`.

### `getPageCount(): int`

[](#getpagecount-int)

Return the total number of pages that would be included in the output (honours page-range filters).

```
$combiner
    ->addFile('doc.pdf', [2, 4])
    ->addFile('summary.pdf');

echo $combiner->getPageCount(); // 2 + all pages of summary.pdf
```

### `getFileCount(): int`

[](#getfilecount-int)

Return the number of files currently queued.

### `reset(): self`

[](#reset-self)

Clear all queued files. Preserves orientation / unit / paper size so the same configured instance can be reused.

```
$combiner->reset();
```

### `resetConfig(): self`

[](#resetconfig-self)

Restore orientation / unit / paper size to their defaults (`P` / `mm` / `A4`). Does not touch the file queue.

```
$combiner->resetConfig();
```

---

Configuration
-------------

[](#configuration)

### Orientation

[](#orientation)

```
use PdfCombine\Contracts\PDFCombinerInterface;

$combiner->withOrientation(PDFCombinerInterface::ORIENTATION_PORTRAIT);   // 'P'
$combiner->withOrientation(PDFCombinerInterface::ORIENTATION_LANDSCAPE);  // 'L'
```

### Unit of measurement

[](#unit-of-measurement)

```
$combiner->withUnit(PDFCombinerInterface::UNIT_MM);
$combiner->withUnit(PDFCombinerInterface::UNIT_CM);
$combiner->withUnit(PDFCombinerInterface::UNIT_IN);
$combiner->withUnit(PDFCombinerInterface::UNIT_PT);
```

### Paper size

[](#paper-size)

```
// Named constants
$combiner->withPaperSize(PDFCombinerInterface::SIZE_A4);
$combiner->withPaperSize(PDFCombinerInterface::SIZE_A5);
$combiner->withPaperSize(PDFCombinerInterface::SIZE_A6);
$combiner->withPaperSize(PDFCombinerInterface::SIZE_LETTER);
$combiner->withPaperSize(PDFCombinerInterface::SIZE_LEGAL);

// Or any TCPDF-compatible format string
$combiner->withPaperSize('A3');
$combiner->withPaperSize('Legal');

// Or custom [width, height] array (in the unit defined above)
$combiner->withPaperSize([210, 297]); // A4 in mm
```

### Laravel config (`config/pdfcombine.php`)

[](#laravel-config-configpdfcombinephp)

```
return [
    'orientation' => env('PDFCOMBINE_ORIENTATION', 'P'),
    'unit'        => env('PDFCOMBINE_UNIT', 'mm'),
    'paper_size'  => env('PDFCOMBINE_PAPER_SIZE', 'A4'),
];
```

Environment variables override the defaults:

```
PDFCOMBINE_ORIENTATION=L
PDFCOMBINE_UNIT=in
PDFCOMBINE_PAPER_SIZE=Letter
```

---

Fluent interface
----------------

[](#fluent-interface)

All setter and adder methods return `$this`, so you can chain calls:

```
$content = $combiner
    ->withOrientation(PDFCombinerInterface::ORIENTATION_LANDSCAPE)
    ->withPaperSize(PDFCombinerInterface::SIZE_A3)
    ->addFile('cover.pdf')
    ->addFile('body.pdf', range(2, 10))
    ->addFile('back.pdf')
    ->stream();
```

---

Error handling
--------------

[](#error-handling)

The package throws typed exceptions from `PdfCombine\Exceptions\PDFCombineException`:

MethodException messageFile not found`PDF file not found at path: ...`Invalid / unreadable PDF`The file at '...' is not a valid PDF or could not be read.`No files added`No PDF files have been added to combine.`Save failed`Failed to save the combined PDF to: ...`Page out of range`Requested page X is out of range. The document has Y pages.````
use PdfCombine\Exceptions\PDFCombineException;

try {
    $combiner->addFile('/missing.pdf')->save('/out.pdf');
} catch (PDFCombineException $e) {
    logger()->error('PDF combine failed: ' . $e->getMessage());
}
```

---

Changelog
---------

[](#changelog)

See the [releases page](https://github.com/tudorr89/pdfcombiner/releases) on GitHub.

---

License
-------

[](#license)

MIT — see the [LICENSE](LICENSE) file for details.

###  Health Score

39

—

LowBetter than 84% of packages

Maintenance86

Actively maintained with recent releases

Popularity7

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity48

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

3

Last Release

70d ago

Major Versions

v1.0.0 → v2.0.02026-05-15

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/3405514?v=4)[Tudor Rusu](/maintainers/tudorr89)[@tudorr89](https://github.com/tudorr89)

---

Top Contributors

[![tudorr89](https://avatars.githubusercontent.com/u/3405514?v=4)](https://github.com/tudorr89 "tudorr89 (3 commits)")

---

Tags

laravelpdfTCPDFfpdimergecombine

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/tudorr89-pdfcombiner/health.svg)

```
[![Health](https://phpackages.com/badges/tudorr89-pdfcombiner/health.svg)](https://phpackages.com/packages/tudorr89-pdfcombiner)
```

###  Alternatives

[elibyy/tcpdf-laravel

tcpdf support for Laravel 6, 7, 8, 9, 10, 11

3632.9M8](/packages/elibyy-tcpdf-laravel)[bithost-gmbh/pdfviewhelpers

This is a TYPO3 CMS extension that provides various Fluid ViewHelpers to generate PDF documents.

45262.7k3](/packages/bithost-gmbh-pdfviewhelpers)[tarfin-labs/easy-pdf

Makes pdf processing easy.

1719.9k](/packages/tarfin-labs-easy-pdf)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
