PHPackages                             endroid/pdf - 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. endroid/pdf

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

endroid/pdf
===========

Endroid PDF

1.6.0(1y ago)3545.4k↓34.6%6MITPHPPHP ^8.2CI passing

Since Jan 11Pushed 2mo ago3 watchersCompare

[ Source](https://github.com/endroid/pdf)[ Packagist](https://packagist.org/packages/endroid/pdf)[ Docs](https://github.com/endroid/pdf)[ GitHub Sponsors](https://github.com/endroid)[ RSS](/packages/endroid-pdf/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (8)Versions (30)Used By (0)

PDF
===

[](#pdf)

*By [endroid](https://endroid.nl/)*

[![Latest Stable Version](https://camo.githubusercontent.com/31f22f89b4e70e0cc1554b42688155970bcfead2af68bad0b1b53aa96f78368c/687474703a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f656e64726f69642f7064662e737667)](https://packagist.org/packages/endroid/pdf)[![Build Status](https://github.com/endroid/pdf/workflows/CI/badge.svg)](https://github.com/endroid/pdf/actions)[![Total Downloads](https://camo.githubusercontent.com/da00b9d53f2d78003f85751e727fe5daf28f6c792abb18e1c9c7daac4c600018/687474703a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f656e64726f69642f7064662e737667)](https://packagist.org/packages/endroid/pdf)[![License](https://camo.githubusercontent.com/eb4f8a4fad61b0d02e12936418efe781ef073a9ef8616f34e14541694d009999/687474703a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f656e64726f69642f7064662e737667)](https://packagist.org/packages/endroid/pdf)

Library for easy PDF generation built around wkhtmltopdf and Snappy. Click [here](https://endroid.nl/play/pdf) for an example. Please note this example takes some time to load because it contains a lot of pages and no caching is applied.

Read the [blog](https://medium.com/@endroid/pdf-generation-in-symfony-3080702353b)for more information on why I created this library and how to use it.

Easy data loading
-----------------

[](#easy-data-loading)

When you generate a PDF you need to make sure you pass the right contents to the PDF object. This data can come from any source (a file, a URL, a controller) and some of these impose a performance hit so you often want to cache some of these contents instead of loading the data every time you generate the PDF.

The [endroid/asset](https://github.com/endroid/asset) takes this burden away by allowing you to define your assets via a simple array of options. The asset factory and guesser make sure the right type of asset is created and even provide a so called cache asset that wraps any other asset.

```
$this->pdfBuilder
    ->setCover([
        'controller' => CoverController::class,
        'parameters' => ['title' => 'My PDF', 'date' => new DateTime()],
        'cache_key' => 'cover',
        'cache_expires_after' => 3600,
        'cache_clear' => true, // use to purge any previously cached data
    ])
;
```

For more information [read the documentation](https://github.com/endroid/asset).

Handling external resources
---------------------------

[](#handling-external-resources)

An HTML page can contain a number of external resources, each triggering a separate request. However during PDF generation this can lead to performance or even stability issues. Therefor we need the number of requests to be as low as possible.

The [endroid/embed](https://github.com/endroid/embed) library helps you minimize the number of assets to load during PDF generation by allowing you to embed external resources via a Twig extension. You can use this extension to embed resources like fonts, stylesheets and scripts.

```

@font-face {
    font-family: 'SCP';
    font-weight: normal;
    src: url('{{ embed('https://fontlibrary.org/scp.ttf') }}');
}

```

For more information you can [read the documentation](https://github.com/endroid/embed).

The PDF builder
---------------

[](#the-pdf-builder)

When [endroid/installer](https://github.com/endroid/installer) detects Symfony the builder is automatically wired and you can immediately start using it to build a PDF. This is an example of how you can use the builder.

```
$pdfBuilder
    ->setCover([
        'controller' => CoverController::class,
        'cache_key' => 'cover',
        'cache_expires_after' => 3600,
    ])
    ->setTableOfContents([
        'path' => '/var/www/html/table_of_contents.xml',
        'cache_key' => 'toc',
    ])
    ->setHeader([
        'template' => 'pdf/header.html.twig',
        'cache_key' => 'header',
    ])
    ->setFooter([
        'template' => 'pdf/footer.html.twig',
        'cache_key' => 'footer',
    ])
    ->setContent([
        'url' => 'http://endroid.nl/',
        'cache_key' => 'content',
    ])
    ->setOptions([
        'margin-top' => 16,
        'margin-bottom' => 16,
        'header-spacing' => 5,
        'footer-spacing' => 5,
    ])
;

$pdf = $pdfBuilder->getPdf();

// Create a response object
$response = InlinePdfResponse::createFromPdf($pdf);

// Or output directly
header('Content-type: application/pdf');
echo $pdf->generate();
```

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

[](#installation)

Use [Composer](https://getcomposer.org/) to install the library.

```
$ composer require endroid/pdf
```

### Symfony

[](#symfony)

When you use Symfony, the [installer](https://github.com/endroid/installer)makes sure that services are automatically wired. If the Snappy\\Pdf service is not registered yet, make sure you create a service definition for it or install the knplabs/snappy-bundle along with the library.

```
$ composer require endroid/pdf knplabs/knp-snappy-bundle
```

Also, if any of the asset types is unsupported (for instance because you have no cache component or Twig available) or if you simply don't want some to be registered you can uncomment the adapter via the service configuration.

### Bootstrapping the PDF builder

[](#bootstrapping-the-pdf-builder)

When no autowiring is available you need to instantiate and wire the necessary dependencies yourself. You can do so via a bootstrap file for instance.

```
$snappy = new Snappy(__DIR__.'/../vendor/h4cc/wkhtmltopdf-amd64/bin/wkhtmltopdf-amd64');

$assetFactory = new AssetFactory();
$assetFactory->add(new DataAssetFactoryAdapter());
$assetFactory->add(new ControllerAssetFactoryAdapter($kernel, $requestStack));
$assetFactory->add(new TemplateAssetFactoryAdapter($twig));
...

$pdfBuilder = new PdfBuilder(new Pdf($snappy), $assetFactory);
```

Versioning
----------

[](#versioning)

Version numbers follow the MAJOR.MINOR.PATCH scheme. Backwards compatible changes will be kept to a minimum but be aware that these can occur. Lock your dependencies for production and test your code when upgrading.

License
-------

[](#license)

This bundle is under the MIT license. For the full copyright and license information please view the LICENSE file that was distributed with this source code.

###  Health Score

55

—

FairBetter than 98% of packages

Maintenance63

Regular maintenance activity

Popularity40

Moderate usage in the ecosystem

Community11

Small or concentrated contributor base

Maturity86

Battle-tested with a long release history

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

Recently: every ~105 days

Total

29

Last Release

575d ago

PHP version history (7 changes)1.0.0PHP &gt;=7.1

1.1.0PHP &gt;=7.2

1.3.0PHP ^7.4||^8.0

1.3.1PHP ^7.3||^8.0

1.5.0PHP ^8.0

1.5.1PHP ^8.1

1.6.0PHP ^8.2

### Community

Maintainers

![](https://www.gravatar.com/avatar/ea3fc1b297f29579f9861b5fbe3240c0eeafaaaee6e39b45d85d612a04a52fbd?d=identicon)[endroid](/maintainers/endroid)

---

Top Contributors

[![endroid](https://avatars.githubusercontent.com/u/537253?v=4)](https://github.com/endroid "endroid (86 commits)")

---

Tags

pdfendroid

### Embed Badge

![Health badge](/badges/endroid-pdf/health.svg)

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

###  Alternatives

[barryvdh/laravel-snappy

Snappy PDF/Image for Laravel

2.8k24.8M48](/packages/barryvdh-laravel-snappy)[knplabs/knp-snappy-bundle

Easily create PDF and images in Symfony by converting Twig/HTML templates.

1.2k31.8M49](/packages/knplabs-knp-snappy-bundle)[sensiolabs/gotenberg-bundle

A Symfony bundle that provides seamless integration with Gotenberg for generating PDFs and screenshots from various sources (HTML, Markdown, Office documents, URLs) with a clean, builder-based API.

210210.4k2](/packages/sensiolabs-gotenberg-bundle)[nucleos/dompdf-bundle

This bundle provides a wrapper for using dompdf inside symfony.

54882.8k1](/packages/nucleos-dompdf-bundle)[danielboendergaard/phantom-pdf

A Package for generating PDF files using PhantomJS

72467.9k](/packages/danielboendergaard-phantom-pdf)[pontedilana/weasyprint-bundle

Easily create PDF in Symfony by converting Twig/HTML templates.

40774.4k](/packages/pontedilana-weasyprint-bundle)

PHPackages © 2026

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