PHPackages                             faradey/tcpdi - 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. faradey/tcpdi

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

faradey/tcpdi
=============

TCPDI is a PHP class for importing PDF to use with TCPDF

2.0.0(4mo ago)212.8k↑103.6%Apache-2.0PHPPHP &gt;=7.4

Since Apr 5Pushed 4mo agoCompare

[ Source](https://github.com/extmag/tcpdi)[ Packagist](https://packagist.org/packages/faradey/tcpdi)[ RSS](/packages/faradey-tcpdi/feed)WikiDiscussions master Synced yesterday

READMEChangelog (6)Dependencies (2)Versions (12)Used By (0)

TCPDI
=====

[](#tcpdi)

PDF importer for [TCPDF](http://www.tcpdf.org/), based on [FPDI](http://www.setasign.de/products/pdf-php-solutions/fpdi/). Includes [tcpdi\_parser](https://github.com/pauln/tcpdi_parser) and [FPDF\_TPL](http://www.setasign.de/products/pdf-php-solutions/fpdi/downloads/).

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

[](#requirements)

- PHP &gt;= 7.4 (compatible with PHP 8.0 — 8.5)
- TCPDF ^6.2.1

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

[](#installation)

```
composer require faradey/tcpdi
```

Usage
-----

[](#usage)

Usage is essentially the same as FPDI, except importing TCPDI rather than FPDI. It also has a `setSourceData()` function which accepts raw PDF data, for cases where the file does not reside on disk or is not readable by TCPDI.

```
// Create new PDF document.
$pdf = new TCPDI(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);

// Add a page from a PDF by file path.
$pdf->AddPage();
$pdf->setSourceFile('/path/to/file-to-import.pdf');
$idx = $pdf->importPage(1);
$pdf->useTemplate($idx);

// Or load from raw PDF data.
$pdfdata = file_get_contents('/path/to/other-file.pdf');
$pagecount = $pdf->setSourceData($pdfdata);
for ($i = 1; $i importPage($i);
    $pdf->AddPage();
    $pdf->useTemplate($tplidx);
}
```

### Annotations

[](#annotations)

TCPDI includes functionality for handling PDF annotations. As annotations are positioned relative to the bleed box rather than the crop box, you'll need to import the full bleed box. A `setPageFormatFromTemplatePage()` function sets the page format from the imported page:

```
$pdf = new TCPDI(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);

$pdf->setSourceFile('/path/to/file-to-import.pdf');

// Import the bleed box (default is crop box) for page 1.
$tplidx = $pdf->importPage(1, '/BleedBox');
$size = $pdf->getTemplateSize($tplidx);
$orientation = ($size['w'] > $size['h']) ? 'L' : 'P';

$pdf->AddPage($orientation);
$pdf->setPageFormatFromTemplatePage(1, $orientation);
$pdf->useTemplate($tplidx);
$pdf->importAnnotations(1);
```

### Page size adjustment

[](#page-size-adjustment)

Use `adjustPageSize` to automatically match the output page size to the imported template:

```
$pdf = new TCPDI();
$pdf->setSourceFile('/path/to/file.pdf');
$pdf->AddPage();
$tplidx = $pdf->importPage(1);
$pdf->useTemplate($tplidx, null, null, 0, 0, true);
```

### Adding images on imported pages

[](#adding-images-on-imported-pages)

You can overlay images (PNG, GIF, JPEG) on imported pages using TCPDF's `Image()` method:

```
$pdf = new TCPDI();
$pdf->setSourceData($pdfdata);
$pdf->AddPage();
$tplidx = $pdf->importPage(1);
$pdf->useTemplate($tplidx);
$pdf->Image('/path/to/image.png', 10, 10, 50, 50, 'PNG');
$pdf->Output('/path/to/output.pdf', 'F');
```

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

[](#error-handling)

Parser errors throw `\RuntimeException` instead of calling `die()`:

```
try {
    $pdf = new TCPDI();
    $pdf->setSourceData($pdfdata);
    $tplidx = $pdf->importPage(1);
} catch (\RuntimeException $e) {
    // Handle invalid/corrupted PDF
    echo $e->getMessage();
}
```

Testing
-------

[](#testing)

```
composer install
./vendor/bin/phpunit
```

TCPDI\_PARSER
=============

[](#tcpdi_parser)

Parser for use with TCPDI, based on TCPDF\_PARSER. Supports PDFs up to v1.7.

###  Health Score

50

—

FairBetter than 95% of packages

Maintenance74

Regular maintenance activity

Popularity28

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity70

Established project with proven stability

 Bus Factor2

2 contributors hold 50%+ of commits

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 ~399 days

Recently: every ~469 days

Total

10

Last Release

145d ago

Major Versions

1.0.9 → 2.0.02026-02-07

PHP version history (3 changes)1.0.0PHP &gt;=5.3.0

1.0.7PHP &gt;=5.6.0

2.0.0PHP &gt;=7.4

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/61543096?v=4)[Faradey](/maintainers/Faradey)[@faradey](https://github.com/faradey)

---

Top Contributors

[![faradey](https://avatars.githubusercontent.com/u/61543096?v=4)](https://github.com/faradey "faradey (22 commits)")[![DJTripper](https://avatars.githubusercontent.com/u/18283090?v=4)](https://github.com/DJTripper "DJTripper (10 commits)")[![kulbakin](https://avatars.githubusercontent.com/u/817433?v=4)](https://github.com/kulbakin "kulbakin (5 commits)")[![rhabkg](https://avatars.githubusercontent.com/u/146323538?v=4)](https://github.com/rhabkg "rhabkg (5 commits)")[![pauln](https://avatars.githubusercontent.com/u/574359?v=4)](https://github.com/pauln "pauln (4 commits)")[![lduer](https://avatars.githubusercontent.com/u/3307025?v=4)](https://github.com/lduer "lduer (1 commits)")

---

Tags

pdfTCPDFtcpditcpdi\_parser

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/faradey-tcpdi/health.svg)

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

###  Alternatives

[elibyy/tcpdf-laravel

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

3632.9M8](/packages/elibyy-tcpdf-laravel)[propa/tcpdi

TCPDI is a PHP class for importing PDF to use with TCPDF

271.2M1](/packages/propa-tcpdi)[bithost-gmbh/pdfviewhelpers

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

45262.7k3](/packages/bithost-gmbh-pdfviewhelpers)[qipsius/tcpdf-bundle

A bundle to easily integrate TCPDF into Symfony

23772.8k](/packages/qipsius-tcpdf-bundle)[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)
